725
726
# Get rid of the status line
726
727
status_and_headers.readline()
727
728
msg = parse_headers(status_and_headers)
730
734
def get_response(self, a_response):
731
735
"""Process a supplied response, and return the result."""
732
736
code, raw_headers, body = a_response
733
msg = self._build_HTTPMessage(raw_headers)
734
return response.handle_response('http://foo', code, msg,
735
BytesIO(a_response[2]))
737
getheader = self._build_HTTPMessage(raw_headers)
738
return response.handle_response(
739
'http://foo', code, getheader, BytesIO(a_response[2]))
737
741
def test_full_text(self):
738
742
out = self.get_response(_full_text_response)
783
787
def test_full_text_no_content_type(self):
784
788
# We should not require Content-Type for a full response
785
789
code, raw_headers, body = _full_text_response_no_content_type
786
msg = self._build_HTTPMessage(raw_headers)
787
out = response.handle_response('http://foo', code, msg, BytesIO(body))
790
getheader = self._build_HTTPMessage(raw_headers)
791
out = response.handle_response(
792
'http://foo', code, getheader, BytesIO(body))
788
793
self.assertEqual(body, out.read())
790
795
def test_full_text_no_content_length(self):
791
796
code, raw_headers, body = _full_text_response_no_content_length
792
msg = self._build_HTTPMessage(raw_headers)
793
out = response.handle_response('http://foo', code, msg, BytesIO(body))
797
getheader = self._build_HTTPMessage(raw_headers)
798
out = response.handle_response(
799
'http://foo', code, getheader, BytesIO(body))
794
800
self.assertEqual(body, out.read())
796
802
def test_missing_content_range(self):
797
803
code, raw_headers, body = _single_range_no_content_range
798
msg = self._build_HTTPMessage(raw_headers)
804
getheader = self._build_HTTPMessage(raw_headers)
799
805
self.assertRaises(errors.InvalidHttpResponse,
800
806
response.handle_response,
801
'http://bogus', code, msg, BytesIO(body))
807
'http://bogus', code, getheader, BytesIO(body))
803
809
def test_multipart_no_content_range(self):
804
810
code, raw_headers, body = _multipart_no_content_range
805
msg = self._build_HTTPMessage(raw_headers)
811
getheader = self._build_HTTPMessage(raw_headers)
806
812
self.assertRaises(errors.InvalidHttpResponse,
807
813
response.handle_response,
808
'http://bogus', code, msg, BytesIO(body))
814
'http://bogus', code, getheader, BytesIO(body))
810
816
def test_multipart_no_boundary(self):
811
817
out = self.get_response(_multipart_no_boundary)