mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 10:16:27 +00:00
Unravel enormously long read_request into three distinct methods.
This commit is contained in:
parent
57f01ffb07
commit
a74ca40660
@ -261,9 +261,7 @@ class ProxyHandler(tcp.BaseHandler):
|
||||
if sn:
|
||||
self.sni = sn.decode("utf8").encode("idna")
|
||||
|
||||
def read_request(self, client_conn):
|
||||
self.rfile.reset_timestamps()
|
||||
if self.config.transparent_proxy:
|
||||
def read_request_transparent(self, client_conn):
|
||||
orig = self.config.transparent_proxy["resolver"].original_addr(self.connection)
|
||||
if not orig:
|
||||
raise ProxyError(502, "Transparent mode failure: could not resolve original destination.")
|
||||
@ -289,8 +287,12 @@ class ProxyHandler(tcp.BaseHandler):
|
||||
content = http.read_http_body_request(
|
||||
self.rfile, self.wfile, headers, httpversion, self.config.body_size_limit
|
||||
)
|
||||
return flow.Request(client_conn, httpversion, host, port, scheme, method, path, headers, content, self.rfile.first_byte_timestamp, utils.timestamp())
|
||||
elif self.config.reverse_proxy:
|
||||
return flow.Request(
|
||||
client_conn,httpversion, host, port, scheme, method, path, headers, content,
|
||||
self.rfile.first_byte_timestamp, utils.timestamp()
|
||||
)
|
||||
|
||||
def read_request_reverse(self, client_conn):
|
||||
line = self.get_line(self.rfile)
|
||||
if line == "":
|
||||
return None
|
||||
@ -303,8 +305,13 @@ class ProxyHandler(tcp.BaseHandler):
|
||||
content = http.read_http_body_request(
|
||||
self.rfile, self.wfile, headers, httpversion, self.config.body_size_limit
|
||||
)
|
||||
return flow.Request(client_conn, httpversion, host, port, "http", method, path, headers, content, self.rfile.first_byte_timestamp, utils.timestamp())
|
||||
else:
|
||||
return flow.Request(
|
||||
client_conn, httpversion, host, port, "http", method, path, headers, content,
|
||||
self.rfile.first_byte_timestamp, utils.timestamp()
|
||||
)
|
||||
|
||||
|
||||
def read_request_proxy(self, client_conn):
|
||||
line = self.get_line(self.rfile)
|
||||
if line == "":
|
||||
return None
|
||||
@ -341,7 +348,10 @@ class ProxyHandler(tcp.BaseHandler):
|
||||
content = http.read_http_body_request(
|
||||
self.rfile, self.wfile, headers, httpversion, self.config.body_size_limit
|
||||
)
|
||||
return flow.Request(client_conn, httpversion, host, port, "https", method, path, headers, content, self.rfile.first_byte_timestamp, utils.timestamp())
|
||||
return flow.Request(
|
||||
client_conn, httpversion, host, port, "https", method, path, headers, content,
|
||||
self.rfile.first_byte_timestamp, utils.timestamp()
|
||||
)
|
||||
else:
|
||||
r = http.parse_init_proxy(line)
|
||||
if not r:
|
||||
@ -351,7 +361,19 @@ class ProxyHandler(tcp.BaseHandler):
|
||||
content = http.read_http_body_request(
|
||||
self.rfile, self.wfile, headers, httpversion, self.config.body_size_limit
|
||||
)
|
||||
return flow.Request(client_conn, httpversion, host, port, scheme, method, path, headers, content, self.rfile.first_byte_timestamp, utils.timestamp())
|
||||
return flow.Request(
|
||||
client_conn, httpversion, host, port, scheme, method, path, headers, content,
|
||||
self.rfile.first_byte_timestamp, utils.timestamp()
|
||||
)
|
||||
|
||||
def read_request(self, client_conn):
|
||||
self.rfile.reset_timestamps()
|
||||
if self.config.transparent_proxy:
|
||||
return self.read_request_transparent(client_conn)
|
||||
elif self.config.reverse_proxy:
|
||||
return self.read_request_reverse(client_conn)
|
||||
else:
|
||||
return self.read_request_proxy(client_conn)
|
||||
|
||||
def read_headers(self, authenticate=False):
|
||||
headers = http.read_headers(self.rfile)
|
||||
|
Loading…
Reference in New Issue
Block a user