def runTest(self): """Tests parsing of the response.""" request = RequestMessage() response = ResponseMessage(request) text = response.feed(self.post_response) self.assertEqual(text, b'') self.assertTrue(response.complete()) self.assertEqual(response.code, 200) self.assertEqual(response.header.version, b"HTTP/1.1")
def runTest(self): """Tests parsing of a broken response.""" p = RequestMessage() text = p.feed(self.request) self.assertEqual(text, b'') self.assertTrue(p.complete()) p = ResponseMessage(p) text = p.feed(self.response) self.assertEqual(text, b'') self.assertTrue(p.complete()) self.assertEqual(p.code, 404) self.assertEqual(p.header.version, b"HTTP/1.1")
def runTest(self): """Tests parsing of POST requests and responses.""" p = RequestMessage() text = p.feed(self.post_request) self.assertEqual(text, b'') self.assertTrue(p.complete()) p = ResponseMessage(p) text = p.feed(self.post_response) self.assertEqual(text, b'') self.assertTrue(p.complete()) self.assertEqual(p.code, 204) self.assertEqual(p.header.version, b"HTTP/1.0") self.assertEqual(p.header.phrase, b"No Content")
def runTest(self): """Constructs a RequestMessage and ResponseMessage and uses them to parse HEAD messages.""" p = RequestMessage() text = p.feed(head_request) self.assertEqual(text, b'') self.assertTrue(p.complete()) self.assertEqual(head_request, p.get_decoded_message()) p = ResponseMessage(p) text = p.feed(head_response) self.assertEqual(text, b'') self.assertTrue(p.complete()) self.assertEqual(head_response, p.get_decoded_message()) self.assertEqual(p.code, 200) self.assertEqual(p.header.version, b"HTTP/1.1") self.assertEqual(p.header.phrase, b"OK")
def runTest(self): """Attempts to parse the contents of get_request and get_response.""" p = RequestMessage() for t in get_request: text = p.feed(t) self.assertEqual(text, '') self.assertTrue(p.headers_complete()) self.assertTrue(p.complete()) self.assertEqual(get_request, p.get_decoded_message()) p = ResponseMessage(p) for char in get_response: text = p.feed(char) self.assertEqual(text, '') self.assertTrue(p.headers_complete()) self.assertTrue(p.complete()) self.assertEqual(get_response, p.get_decoded_message()) self.assertEqual("tests", p.get_body())
def runTest(self): """Attempts to parse get_request_lines, i.e. get_request line at a time.""" p = RequestMessage() for line in get_request_lines[:-1]: text = p.feed(line) self.assertEqual(text, b"") text = p.feed(b"\r\n") self.assertEqual(text, b"") text = p.feed(get_request_lines[-1]) self.assertEqual(text, b"") self.assertTrue(p.headers_complete()) self.assertTrue(p.complete()) self.assertEqual(get_request, p.get_decoded_message()) p = ResponseMessage(p) for line in get_response_lines[:-1]: text = p.feed(line) self.assertEqual(text, b"") text = p.feed(b"\r\n") self.assertEqual(text, b"") text = p.feed(get_response_lines[-1]) self.assertEqual(text, b"") self.assertTrue(p.headers_complete()) self.assertTrue(p.complete()) self.assertEqual(get_response, p.get_decoded_message()) self.assertEqual(p.code, 200) self.assertEqual(p.header.version, b"HTTP/1.1") self.assertEqual(p.header.phrase, b"OK")
def runTest(self): """Attempts to parse the contents of get_request and get_response.""" p = RequestMessage() for t in get_request: if isinstance(t, int): t = bytes([t]) # python3 text = p.feed(t) self.assertEqual(text, b'') self.assertTrue(p.headers_complete()) self.assertTrue(p.complete()) self.assertEqual(get_request, p.get_decoded_message()) p = ResponseMessage(p) for char in get_response: if isinstance(char, int): char = bytes([char]) # python3 text = p.feed(char) self.assertEqual(text, b'') self.assertTrue(p.headers_complete()) self.assertTrue(p.complete()) self.assertEqual(get_response, p.get_decoded_message()) self.assertEqual(b"tests", p.get_body())