Exemplo n.º 1
0
    async def start(self, connection, read_until_eof=False):
        """Start response processing."""
        self._setup_connection(connection)
        message = None

        while True:
            httpstream = self._reader.set_parser(self._response_parser)

            # read response
            message = await httpstream.read()
            if message.code != 100:
                break

            if self._continue is not None and not self._continue.done():
                self._continue.set_result(True)
                self._continue = None

        # response status
        self.version = message.version
        self.status = message.code
        self.reason = message.reason
        self._should_close = message.should_close

        # headers
        self.headers = CIMultiDictProxy(message.headers)

        # payload
        response_with_body = self._need_parse_response_body()
        self._reader.set_parser(
            aiohttp.HttpPayloadParser(message,
                                      compression=False,
                                      readall=read_until_eof,
                                      response_with_body=response_with_body),
            self.content)

        # cookies
        self.cookies = http.cookies.SimpleCookie()
        if aiohttp.client.hdrs.SET_COOKIE in self.headers:
            for hdr in self.headers.getall(aiohttp.client.hdrs.SET_COOKIE):
                try:
                    self.cookies.load(hdr)
                except http.cookies.CookieError as exc:
                    aiohttp.log.client_logger.warning(
                        'Can not load response cookies: %s', exc)
        return self
Exemplo n.º 2
0
class ReverseProxyResponse(aiohttp.client.ClientResponse):
    """
    aiohttp's default response class decompresses the response body on the fly;
    a reverse proxy wants to return it to its client verbatim. so this class
    exists in order that the payload parser instantiated in this method can be
    instantiated without the decompression feature. it isn't otherwise
    interesting.
    """
    async def start(self, connection, read_until_eof=False):
        """Start response processing."""
        self._setup_connection(connection)
        message = None

        while True:
            httpstream = self._reader.set_parser(self._response_parser)

            # read response
            message = await httpstream.read()
            if message.code != 100:
                break

            if self._continue is not None and not self._continue.done():
                self._continue.set_result(True)
                self._continue = None

        # response status
        self.version = message.version
        self.status = message.code
        self.reason = message.reason
        self._should_close = message.should_close

        # headers
        self.headers = CIMultiDictProxy(message.headers)

        # payload
        response_with_body = self._need_parse_response_body()
        self._reader.set_parser(
            aiohttp.HttpPayloadParser(
                message,
                compression=False,
                readall=read_until_eof,
                response_with_body=response_with_body),
            self.content
        )

        # cookies
        self.cookies = http.cookies.SimpleCookie()
        if aiohttp.client.hdrs.SET_COOKIE in self.headers:
            for hdr in self.headers.getall(aiohttp.client.hdrs.SET_COOKIE):
                try:
                    self.cookies.load(hdr)
                except http.cookies.CookieError as exc:
                    aiohttp.log.client_logger.warning(
                        'Can not load response cookies: %s', exc)
        return self
Exemplo n.º 3
0
class ReverseProxyResponse(aiohttp.client.ClientResponse):
    """
    aiohttp's default response class decompresses the response body on the fly;
    a reverse proxy wants to return it to its client verbatim. so this class
    exists in order that the payload parser instantiated in this method can be
    instantiated without the decompression feature. it isn't otherwise
    interesting.
    """
    async def start(self, connection, read_until_eof=False):
        """Start response processing."""
        self._setup_connection(connection)
        message = None

        while True:
            httpstream = self._reader.set_parser(self._response_parser)

            # read response
            message = await httpstream.read()
            if message.code != 100:
                break

            if self._continue is not None and not self._continue.done():
                self._continue.set_result(True)
                self._continue = None

        # response status
        self.version = message.version
        self.status = message.code
        self.reason = message.reason
        self._should_close = message.should_close

        # headers
        self.headers = CIMultiDictProxy(message.headers)

        # payload
        response_with_body = self._need_parse_response_body()
        self._reader.set_parser(
            aiohttp.HttpPayloadParser(message,
                                      compression=False,
                                      readall=read_until_eof,
                                      response_with_body=response_with_body),
            self.content)

        # cookies
        self.cookies = http.cookies.SimpleCookie()
        if aiohttp.client.hdrs.SET_COOKIE in self.headers:
            for hdr in self.headers.getall(aiohttp.client.hdrs.SET_COOKIE):
                try:
                    self.cookies.load(hdr)
                except http.cookies.CookieError as exc:
                    aiohttp.log.client_logger.warning(
                        'Can not load response cookies: %s', exc)
        return self
Exemplo n.º 4
0
    async def start(self, connection, read_until_eof=False):
        """Start response processing."""
        self._setup_connection(connection)
        message = None

        while True:
            httpstream = self._reader.set_parser(self._response_parser)

            # read response
            message = await httpstream.read()
            if message.code != 100:
                break

            if self._continue is not None and not self._continue.done():
                self._continue.set_result(True)
                self._continue = None

        # response status
        self.version = message.version
        self.status = message.code
        self.reason = message.reason
        self._should_close = message.should_close

        # headers
        self.headers = CIMultiDictProxy(message.headers)

        # payload
        response_with_body = self._need_parse_response_body()
        self._reader.set_parser(
            aiohttp.HttpPayloadParser(
                message,
                compression=False,
                readall=read_until_eof,
                response_with_body=response_with_body),
            self.content
        )

        # cookies
        self.cookies = http.cookies.SimpleCookie()
        if aiohttp.client.hdrs.SET_COOKIE in self.headers:
            for hdr in self.headers.getall(aiohttp.client.hdrs.SET_COOKIE):
                try:
                    self.cookies.load(hdr)
                except http.cookies.CookieError as exc:
                    aiohttp.log.client_logger.warning(
                        'Can not load response cookies: %s', exc)
        return self