def read_request(
        self,
        __rfile,
        include_body=True,
        body_size_limit=None,
        allow_empty=False,
    ):
        if body_size_limit is not None:
            raise NotImplementedError()

        self.perform_connection_preface()

        timestamp_start = time.time()
        if hasattr(self.tcp_handler.rfile, "reset_timestamps"):
            self.tcp_handler.rfile.reset_timestamps()

        stream_id, headers, body = self._receive_transmission(
            include_body=include_body,
        )

        if hasattr(self.tcp_handler.rfile, "first_byte_timestamp"):
            # more accurate timestamp_start
            timestamp_start = self.tcp_handler.rfile.first_byte_timestamp

        timestamp_end = time.time()

        # pseudo header must be present, see https://http2.github.io/http2-spec/#rfc.section.8.1.2.3
        authority = headers.pop(':authority', "")
        method = headers.pop(':method', "")
        scheme = headers.pop(':scheme', "")
        path = headers.pop(':path', "")

        host, port = url.parse_authority(authority, check=False)
        port = port or url.default_port(scheme) or 0

        request = mitmproxy.net.http.Request(
            host=host,
            port=port,
            method=method.encode(),
            scheme=scheme.encode(),
            authority=authority.encode(),
            path=path.encode(),
            http_version=b"HTTP/2.0",
            headers=headers,
            content=body,
            trailers=None,
            timestamp_start=timestamp_start,
            timestamp_end=timestamp_end,
        )
        request.stream_id = stream_id

        return request
Ejemplo n.º 2
0
    def read_response_headers(self):
        self.response_arrived.wait()

        self.raise_zombie()

        status_code = int(self.response_headers.get(':status', 502))
        headers = self.response_headers.copy()
        headers.pop(":status", None)

        return http.HTTPResponse(
            http_version=b"HTTP/2.0",
            status_code=status_code,
            reason=b'',
            headers=headers,
            content=None,
            timestamp_start=self.timestamp_start,
            timestamp_end=self.timestamp_end,
        )
Ejemplo n.º 3
0
    def read_response_headers(self):
        self.response_arrived.wait()

        self.raise_zombie()

        status_code = int(self.response_headers.get(':status', 502))
        headers = self.response_headers.copy()
        headers.pop(":status", None)

        return http.HTTPResponse(
            http_version=b"HTTP/2.0",
            status_code=status_code,
            reason=b'',
            headers=headers,
            content=None,
            timestamp_start=self.timestamp_start,
            timestamp_end=self.timestamp_end,
        )