Example #1
0
    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")
Example #2
0
    def runTest(self):
        print repr(head_request)
        p = RequestMessage()
        text = p.feed(head_request)

        self.assertEqual(text, "")
        print p.mode
        print p.feed_predict()
        self.assertTrue(p.complete())
        self.assertEqual(head_request, p.get_decoded_message())

        print repr(head_response)

        p = ResponseMessage(p)
        text = p.feed(head_response)

        self.assertEqual(text, "")
        self.assertTrue(p.complete())
        self.assertEqual(head_response, p.get_decoded_message())
Example #3
0
    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")
Example #4
0
    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")
Example #5
0
    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")
Example #6
0
    def runTest(self):
        print repr(get_request)
        p = RequestMessage()
        for t in get_request:
            print t
            text = p.feed(t)
            print t, text
            self.assertEqual(text, "")
        self.assertTrue(p.complete())

        self.assertEqual(get_request, p.get_decoded_message())
        print repr(get_response)

        p = ResponseMessage(p)
        text = p.feed(get_response)

        self.assertEqual(text, "")
        self.assertTrue(p.complete())
        self.assertEqual(get_response, p.get_decoded_message())
Example #7
0
    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")
Example #8
0
    def runTest(self):
        print repr(head_request)
        buffer = StringIO()
        p = RequestMessage(buffer)
        text = p.feed(head_request)

        self.assertEqual(text, '')
        self.assertEqual(head_request, buffer.getvalue())
        self.assertTrue(p.complete())
        self.assertEqual(head_request, p.get_canonicalized_message())

        print repr(head_response)

        
        buffer = StringIO()
        p = ResponseMessage(buffer, p.header)
        text = p.feed(head_response)

        self.assertEqual(text, '')
        self.assertEqual(head_response, buffer.getvalue())
        self.assertTrue(p.complete())
        self.assertEqual(head_response, p.get_canonicalized_message())
Example #9
0
    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")
Example #10
0
    def runTest(self):
        print repr(post_request)
        p = RequestMessage()
        text = p.feed(post_request)

        self.assertEqual(text, "")
        self.assertTrue(p.complete())

        print repr(post_response)

        p = ResponseMessage(p)
        text = p.feed(post_response)

        self.assertEqual(text, "")
        self.assertTrue(p.complete())
Example #11
0
    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")
Example #12
0
    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")
Example #13
0
    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())
Example #14
0
    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")
Example #15
0
    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())
Example #16
0
    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())