How to use the httptools.HttpResponseParser function in httptools

To help you get started, we’ve selected a few httptools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MagicStack / httptools / tests / test_parser.py View on Github external
def test_parser_response_1(self):
        m = mock.Mock()

        headers = {}
        m.on_header.side_effect = headers.__setitem__

        p = httptools.HttpResponseParser(m)
        p.feed_data(memoryview(RESPONSE1_HEAD))

        self.assertEqual(p.get_http_version(), '1.1')
        self.assertEqual(p.get_status_code(), 200)

        m.on_status.assert_called_once_with(b'OK')

        m.on_headers_complete.assert_called_once_with()
        self.assertEqual(m.on_header.call_count, 8)
        self.assertEqual(len(headers), 8)
        self.assertEqual(headers.get(b'Connection'), b'close')
        self.assertEqual(headers.get(b'Content-Type'),
                         b'text/html;  charset=UTF-8')

        self.assertFalse(m.on_body.called)
        p.feed_data(bytearray(RESPONSE1_BODY))
github MagicStack / httptools / tests / test_parser.py View on Github external
def test_parser_response_cb_on_status_1(self):
        class Error(Exception):
            pass

        m = mock.Mock()
        m.on_status.side_effect = Error()

        p = httptools.HttpResponseParser(m)
        try:
            p.feed_data(RESPONSE1_HEAD + RESPONSE1_BODY)
        except httptools.HttpParserCallbackError as ex:
            self.assertIsInstance(ex.__context__, Error)
        else:
            self.fail('HttpParserCallbackError was not raised')
github MagicStack / httptools / tests / test_parser.py View on Github external
def test_parser_response_2(self):
        with self.assertRaisesRegex(TypeError, 'a bytes-like object'):
            httptools.HttpResponseParser(None).feed_data('')
github MagicStack / httptools / tests / test_parser.py View on Github external
def test_parser_response_5(self):
        m = mock.Mock()
        m.on_status = None
        m.on_header = None
        m.on_body = None
        m.on_headers_complete = None
        m.on_chunk_header = None
        m.on_chunk_complete = None

        p = httptools.HttpResponseParser(m)
        p.feed_data(RESPONSE1_HEAD)
        p.feed_data(RESPONSE1_BODY)

        m.on_message_complete.assert_called_once_with()
github PeterDing / mugen / mugen / models.py View on Github external
def receive(self):
        http_response = HttpResonse(cookies=self.cookies, encoding=self.encoding)
        http_response_parser = HttpResponseParser(http_response)

        conn = self.connection

        # TODO, handle Maximum amount of incoming data to buffer
        chucks = b''
        while True:
            chuck = yield from conn.readline()
            chucks += chuck
            if chuck == b'\r\n':
                break

        http_response_parser.feed_data(chucks)

        self.status_code = http_response_parser.get_status_code()
        headers = http_response.headers
        self.headers = headers
github BBVA / apicheck / tools / curl / gurl / __init__.py View on Github external
def _build_parser(callbacks):
        return httptools.HttpResponseParser(callbacks)
    def _extract_from_parser(parser):
github RobertoPrevato / BlackSheep / blacksheep / client / connection.py View on Github external
def reset(self):
        self.headers = []
        self.request = None
        self.response = None
        self.writing_paused = False
        self.writable.set()
        self.expect_100_continue = False
        self.parser = httptools.HttpResponseParser(self)
        self._connection_lost = False
        self._pending_task = None
        self._can_release = False
        self._upgraded = False
github RobertoPrevato / BlackSheep / blacksheep / client / connection.py View on Github external
def __init__(self, loop, pool):
        self.loop = loop
        self.pool = weakref.ref(pool)
        self.transport = None
        self.open = False
        self.writing_paused = False
        self.writable = asyncio.Event()
        self.ready = asyncio.Event()
        self.response_ready = asyncio.Event()
        self.expect_100_continue = False
        self.request = None
        self.request_timeout = 20
        self.headers = []
        self.response = None
        self.parser = httptools.HttpResponseParser(self)
        self._connection_lost = False
        self._pending_task = None
        self._can_release = False
        self._upgraded = False
github koursaros-ai / nboost / nboost / proxy / __init__.py View on Github external
def proxy_recv(self, client_socket, server_socket):
        """Receive the proxied response and pipe to the client"""
        handler = BaseHandler(HttpResponseParser)
        self.recv(handler, server_socket, client_socket)