mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
fix: changes to request.host in the request inline script hook are now considered for the server connection
This commit is contained in:
parent
0acda9a684
commit
623cbd4e51
@ -939,7 +939,8 @@ class HTTPHandler(ProtocolHandler, TemporaryServerChangeMixin):
|
|||||||
# sent through to the Master.
|
# sent through to the Master.
|
||||||
flow.request = req
|
flow.request = req
|
||||||
request_reply = self.c.channel.ask("request", flow.request)
|
request_reply = self.c.channel.ask("request", flow.request)
|
||||||
flow.server_conn = self.c.server_conn
|
self.determine_server_address(flow)
|
||||||
|
flow.server_conn = self.c.server_conn # Update server_conn attribute on the flow
|
||||||
|
|
||||||
if request_reply is None or request_reply == KILL:
|
if request_reply is None or request_reply == KILL:
|
||||||
return False
|
return False
|
||||||
@ -990,10 +991,12 @@ class HTTPHandler(ProtocolHandler, TemporaryServerChangeMixin):
|
|||||||
|
|
||||||
flow.timestamp_end = utils.timestamp()
|
flow.timestamp_end = utils.timestamp()
|
||||||
|
|
||||||
if (http.connection_close(flow.request.httpversion, flow.request.headers) or
|
close_connection = (
|
||||||
http.connection_close(flow.response.httpversion, flow.response.headers) or
|
http.connection_close(flow.request.httpversion, flow.request.headers) or
|
||||||
http.expected_http_body_size(flow.response.headers, False, flow.request.method,
|
http.connection_close(flow.response.httpversion, flow.response.headers) or
|
||||||
flow.response.code) == -1):
|
http.expected_http_body_size(flow.response.headers, False, flow.request.method,
|
||||||
|
flow.response.code) == -1)
|
||||||
|
if close_connection:
|
||||||
if flow.request.form_in == "authority" and flow.response.code == 200:
|
if flow.request.form_in == "authority" and flow.response.code == 200:
|
||||||
# Workaround for https://github.com/mitmproxy/mitmproxy/issues/313:
|
# Workaround for https://github.com/mitmproxy/mitmproxy/issues/313:
|
||||||
# Some proxies (e.g. Charles) send a CONNECT response with HTTP/1.0 and no Content-Length header
|
# Some proxies (e.g. Charles) send a CONNECT response with HTTP/1.0 and no Content-Length header
|
||||||
@ -1105,20 +1108,21 @@ class HTTPHandler(ProtocolHandler, TemporaryServerChangeMixin):
|
|||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
elif request.form_in == self.expected_form_in:
|
elif request.form_in == self.expected_form_in:
|
||||||
if request.form_in == "absolute":
|
|
||||||
if request.scheme != "http":
|
|
||||||
raise http.HttpError(400, "Invalid request scheme: %s" % request.scheme)
|
|
||||||
|
|
||||||
self.c.set_server_address((request.host, request.port),
|
|
||||||
proxy.AddressPriority.FROM_PROTOCOL)
|
|
||||||
flow.server_conn = self.c.server_conn # Update server_conn attribute on the flow
|
|
||||||
|
|
||||||
request.form_out = self.expected_form_out
|
request.form_out = self.expected_form_out
|
||||||
return True
|
return True
|
||||||
|
|
||||||
raise http.HttpError(400, "Invalid HTTP request form (expected: %s, got: %s)" %
|
raise http.HttpError(400, "Invalid HTTP request form (expected: %s, got: %s)" %
|
||||||
(self.expected_form_in, request.form_in))
|
(self.expected_form_in, request.form_in))
|
||||||
|
|
||||||
|
def determine_server_address(self, flow):
|
||||||
|
if flow.request.form_in == "absolute":
|
||||||
|
if flow.request.scheme != "http":
|
||||||
|
raise http.HttpError(400, "Invalid request scheme: %s" % flow.request.scheme)
|
||||||
|
|
||||||
|
self.c.set_server_address((flow.request.host, flow.request.port),
|
||||||
|
proxy.AddressPriority.FROM_PROTOCOL)
|
||||||
|
flow.server_conn = self.c.server_conn # Update server_conn attribute on the flow
|
||||||
|
|
||||||
def authenticate(self, request):
|
def authenticate(self, request):
|
||||||
if self.c.config.authenticator:
|
if self.c.config.authenticator:
|
||||||
if self.c.config.authenticator.authenticate(request.headers):
|
if self.c.config.authenticator.authenticate(request.headers):
|
||||||
|
Loading…
Reference in New Issue
Block a user