aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/protocol/http.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2014-08-17 23:59:44 +0200
committerMaximilian Hils <git@maximilianhils.com>2014-08-17 23:59:44 +0200
commit623cbd4e5178833b06d47e6b1a2a146b7f0e85ed (patch)
treea1f2b9fecec7aa7711b6e5d12e34bb79daf4f529 /libmproxy/protocol/http.py
parent0acda9a684b860ff59642d563beda8e10c8cf253 (diff)
downloadmitmproxy-623cbd4e5178833b06d47e6b1a2a146b7f0e85ed.tar.gz
mitmproxy-623cbd4e5178833b06d47e6b1a2a146b7f0e85ed.tar.bz2
mitmproxy-623cbd4e5178833b06d47e6b1a2a146b7f0e85ed.zip
fix: changes to request.host in the request inline script hook are now considered for the server connection
Diffstat (limited to 'libmproxy/protocol/http.py')
-rw-r--r--libmproxy/protocol/http.py30
1 files changed, 17 insertions, 13 deletions
diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py
index 68762833..21d2c7ea 100644
--- a/libmproxy/protocol/http.py
+++ b/libmproxy/protocol/http.py
@@ -939,7 +939,8 @@ class HTTPHandler(ProtocolHandler, TemporaryServerChangeMixin):
# sent through to the Master.
flow.request = req
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:
return False
@@ -990,10 +991,12 @@ class HTTPHandler(ProtocolHandler, TemporaryServerChangeMixin):
flow.timestamp_end = utils.timestamp()
- if (http.connection_close(flow.request.httpversion, flow.request.headers) or
- http.connection_close(flow.response.httpversion, flow.response.headers) or
- http.expected_http_body_size(flow.response.headers, False, flow.request.method,
- flow.response.code) == -1):
+ close_connection = (
+ http.connection_close(flow.request.httpversion, flow.request.headers) or
+ http.connection_close(flow.response.httpversion, flow.response.headers) or
+ 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:
# 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
@@ -1105,20 +1108,21 @@ class HTTPHandler(ProtocolHandler, TemporaryServerChangeMixin):
else:
return True
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
return True
raise http.HttpError(400, "Invalid HTTP request form (expected: %s, got: %s)" %
(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):
if self.c.config.authenticator:
if self.c.config.authenticator.authenticate(request.headers):