Example #1
0
    def process_response(self):
        if self._is_diverted_request:
            return

        try:
            self._remote_headers = unsign_headers(
                self.config,
                self._remote_headers,
            )
        except SignatureError:
            self.critical(
                "Failed to verify response signature, server may be "
                "improperly configured or we are experiencing MITM attack"
            )
            self.dump_info()
            sys.exit(1)

        if self.should_divert:
            fut = self._send_request_future
            fut.cancel()
            yield from asyncio.sleep(0)
            assert fut.done()

            self.destroy_remote_connection()
            self._remote_headers = None
            yield from self.divert_request()
            if self.request_has_body and self._reader.too_much_data:
                yield from self.respond_and_close(
                    code=503,
                    status="Service Unavailable",
                    body="Diverting request, please retry.",
                )
                assert False  # Unreachable

            yield from self.ensure_remote_connection()
            assert self._send_request_future == fut
            self._send_request_future = None
            self.begin_send_request()
            yield from self.read_remote_headers()
Example #2
0
 def try_unsign_readers(self, request):
     try:
         return unsign_headers(self.config, request)
     except SignatureError as e:
         self.debug("Unauthorized request: %s", repr(e))
         return None