aboutsummaryrefslogtreecommitdiffstats
path: root/netlib
diff options
context:
space:
mode:
authorWill Coster <willcoster@google.com>2016-02-15 16:21:20 -0800
committerWill Coster <willcoster@google.com>2016-02-15 16:21:20 -0800
commita69d223b335894a5c9f7c006cf46a0cb4bc0ac43 (patch)
tree3aec893567af03b3683ef147b57d8480fcbe0bef /netlib
parent4583fa79222d9b1d035efa0701fc03525747b46c (diff)
downloadmitmproxy-a69d223b335894a5c9f7c006cf46a0cb4bc0ac43.tar.gz
mitmproxy-a69d223b335894a5c9f7c006cf46a0cb4bc0ac43.tar.bz2
mitmproxy-a69d223b335894a5c9f7c006cf46a0cb4bc0ac43.zip
Preserve host header when modifying request path
Currently the path_components and query setters of the Request object use the url setter under the hood. The url setter updates all parts of the URL including the host. If the host header and the host in the request URL are different (as is common when making HTTPS requests) then the host header will be updated to the value in the URL as a result of modifying the path. This change fixes this problem by modifying the query and path_components setters to not use the url setter and instead directly update the path field.
Diffstat (limited to 'netlib')
-rw-r--r--netlib/netlib/http/request.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/netlib/netlib/http/request.py b/netlib/netlib/http/request.py
index 0e0f88ce..b9076c0f 100644
--- a/netlib/netlib/http/request.py
+++ b/netlib/netlib/http/request.py
@@ -192,7 +192,8 @@ class Request(Message):
def query(self, odict):
query = utils.urlencode(odict.lst)
scheme, netloc, path, params, _, fragment = urllib.parse.urlparse(self.url)
- self.url = urllib.parse.urlunparse([scheme, netloc, path, params, query, fragment])
+ _, _, _, self.path = utils.parse_url(
+ urllib.parse.urlunparse([scheme, netloc, path, params, query, fragment]))
@property
def cookies(self):
@@ -223,7 +224,8 @@ class Request(Message):
components = map(lambda x: urllib.parse.quote(x, safe=""), components)
path = "/" + "/".join(components)
scheme, netloc, _, params, query, fragment = urllib.parse.urlparse(self.url)
- self.url = urllib.parse.urlunparse([scheme, netloc, path, params, query, fragment])
+ _, _, _, self.path = utils.parse_url(
+ urllib.parse.urlunparse([scheme, netloc, path, params, query, fragment]))
def anticache(self):
"""
@@ -350,4 +352,5 @@ class Request(Message):
@form_out.setter
def form_out(self, form_out): # pragma: nocover
warnings.warn(".form_out is deprecated, use .first_line_format instead.", DeprecationWarning)
- self.first_line_format = form_out \ No newline at end of file
+ self.first_line_format = form_out
+