Ejemplo n.º 1
0
    def test_connect(self):
        h = dict([
            (':authority', "127.0.0.1"),
            (':method', 'CONNECT'),
            (':scheme', 'https'),
            (':path', '/'),
        ])

        with pytest.raises(NotImplementedError):
            parse_headers(h)
Ejemplo n.º 2
0
    def test_connect(self):
        h = dict([
            (':authority', "127.0.0.1"),
            (':method', 'CONNECT'),
            (':scheme', 'https'),
            (':path', '/'),
        ])

        with pytest.raises(NotImplementedError):
            parse_headers(h)
Ejemplo n.º 3
0
 def test_without_authority(self):
     h = dict([
         (':method', 'GET'),
         (':scheme', 'https'),
         (':path', '/'),
     ])
     _, _, _, host, _, _ = parse_headers(h)
     assert host == b'localhost'
Ejemplo n.º 4
0
 def test_without_authority(self):
     h = dict([
         (':method', 'GET'),
         (':scheme', 'https'),
         (':path', '/'),
     ])
     _, _, _, host, _, _ = parse_headers(h)
     assert host == b'localhost'
Ejemplo n.º 5
0
 def test_without_port(self, scheme, expected_port):
     h = dict([
         (':authority', "127.0.0.1"),
         (':method', 'GET'),
         (':scheme', scheme),
         (':path', '/'),
     ])
     _, _, _, _, port, _ = parse_headers(h)
     assert port == expected_port
Ejemplo n.º 6
0
 def test_without_port(self, scheme, expected_port):
     h = dict([
         (':authority', "127.0.0.1"),
         (':method', 'GET'),
         (':scheme', scheme),
         (':path', '/'),
     ])
     _, _, _, _, port, _ = parse_headers(h)
     assert port == expected_port
Ejemplo n.º 7
0
 def test_relative(self):
     h = dict([
         (':authority', "127.0.0.1:1234"),
         (':method', 'GET'),
         (':scheme', 'https'),
         (':path', '/'),
     ])
     first_line_format, method, scheme, host, port, path = parse_headers(h)
     assert first_line_format == 'relative'
     assert method == b'GET'
     assert scheme == b'https'
     assert host == b'127.0.0.1'
     assert port == 1234
     assert path == b'/'
Ejemplo n.º 8
0
 def test_relative(self):
     h = dict([
         (':authority', "127.0.0.1:1234"),
         (':method', 'GET'),
         (':scheme', 'https'),
         (':path', '/'),
     ])
     first_line_format, method, scheme, host, port, path = parse_headers(h)
     assert first_line_format == 'relative'
     assert method == b'GET'
     assert scheme == b'https'
     assert host == b'127.0.0.1'
     assert port == 1234
     assert path == b'/'
Ejemplo n.º 9
0
 def read_request_headers(self):
     self.request_arrived.wait()
     self.raise_zombie()
     first_line_format, method, scheme, host, port, path = http2.parse_headers(self.request_headers)
     return http.HTTPRequest(
         first_line_format,
         method,
         scheme,
         host,
         port,
         path,
         b"HTTP/2.0",
         self.request_headers,
         None,
         timestamp_start=self.timestamp_start,
         timestamp_end=self.timestamp_end,
     )
Ejemplo n.º 10
0
    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()

        first_line_format, method, scheme, host, port, path = http2.parse_headers(
            headers)

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

        return request
Ejemplo n.º 11
0
    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()

        first_line_format, method, scheme, host, port, path = http2.parse_headers(headers)

        request = mitmproxy.net.http.request.Request(
            first_line_format,
            method,
            scheme,
            host,
            port,
            path,
            b"HTTP/2.0",
            headers,
            body,
            timestamp_start,
            timestamp_end,
        )
        request.stream_id = stream_id

        return request
Ejemplo n.º 12
0
    def read_request_headers(self, flow):
        self.request_arrived.wait()
        self.raise_zombie()

        if self.pushed:
            flow.metadata['h2-pushed-stream'] = True

        first_line_format, method, scheme, host, port, path = http2.parse_headers(self.request_headers)
        return http.HTTPRequest(
            first_line_format,
            method,
            scheme,
            host,
            port,
            path,
            b"HTTP/2.0",
            self.request_headers,
            None,
            timestamp_start=self.timestamp_start,
            timestamp_end=self.timestamp_end,
        )