def _load_http_request(o: http_pb2.HTTPRequest) -> HTTPRequest: d: dict = {} _move_attrs(o, d, ['host', 'port', 'method', 'scheme', 'authority', 'path', 'http_version', 'content', 'timestamp_start', 'timestamp_end']) if d['content'] is None: d['content'] = b"" d["headers"] = [] for header in o.headers: d["headers"].append((bytes(header.name, "utf-8"), bytes(header.value, "utf-8"))) return HTTPRequest(**d)
def flow(): request = HTTPRequest(first_line_format='first_line', host=b'localhost', path=b'/test/', http_version=b'1.1', port=1234, method=b'', scheme=b'', headers=Headers([(b"Host", b"example.com")]), content=None, timestamp_start=111.1) flow = HTTPFlow(client_conn=MagicMock(), server_conn=MagicMock()) flow.request = request return flow
def to_mitmproxy(self) -> HTTPRequest: parsed_url = urlparse(self.url) return HTTPRequest( first_line_format='absolute', method=self.method, scheme=parsed_url.scheme, host=parsed_url.hostname, port=parsed_url.port or getservbyname(parsed_url.scheme), path=parsed_url.path, http_version=self.http_version, headers=self.headers.to_mitmproxy(), content=self.body, )
'Connection': ['keep-alive'], 'User-Agent': ['python-requests/2.18.4'], }, 'method': 'GET', 'url': 'http://127.0.0.1/test', } TEST_MITM_REQUEST = HTTPRequest( first_line_format='absolute', method='GET', scheme='http', host='127.0.0.1', port=80, path='/test', http_version='HTTP/1.1', headers=[ (b'Content-Type', b'application/json; charset=UTF-8'), (b'Accept-Encoding', b'gzip, deflate'), (b'Connection', b'keep-alive'), (b'User-Agent', b'python-requests/2.18.4'), ], content=b'{"message": "Witaj, \xc5\x9bwiecie!"}' ) TEST_MITM_REQUEST_GZIP = HTTPRequest( first_line_format='absolute', method='GET', scheme='http', host='127.0.0.1', port=80,