diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-10-19 11:41:42 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-10-19 11:41:42 +1300 |
commit | 85015fe561547a51bc229318287920d31caec985 (patch) | |
tree | 0f04a0f65c494e38b31a593586f0919e31fbae7f /pathod | |
parent | ceb8caee9885e87641755e86b72adc2a73877ce0 (diff) | |
download | mitmproxy-85015fe561547a51bc229318287920d31caec985.tar.gz mitmproxy-85015fe561547a51bc229318287920d31caec985.tar.bz2 mitmproxy-85015fe561547a51bc229318287920d31caec985.zip |
pathoc: Guess the Host header from the path if possible
Diffstat (limited to 'pathod')
-rw-r--r-- | pathod/language/http.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/pathod/language/http.py b/pathod/language/http.py index 5d2ff54d..32f990bb 100644 --- a/pathod/language/http.py +++ b/pathod/language/http.py @@ -2,6 +2,7 @@ import abc import pyparsing as pp +from netlib.http import url import netlib.websockets from netlib.http import status_codes, user_agents from . import base, exceptions, actions, message @@ -318,7 +319,7 @@ class Request(_HTTPMessage): ) ) if not self.raw: - if not get_header("Content-Length", self.headers): + if not get_header(b"Content-Length", self.headers): if self.body: length = sum( len(i) for i in self.body.values(settings) @@ -330,11 +331,21 @@ class Request(_HTTPMessage): ) ) if settings.request_host: - if not get_header("Host", self.headers): + if not get_header(b"Host", self.headers): + h = settings.request_host + if self.path: + path = b"".join(self.path.values({})).decode( + "ascii", errors="ignore" + ) + try: + _, h, _, _ = url.parse(path) + h = h.decode("ascii", errors="ignore") + except ValueError: + pass tokens.append( Header( base.TokValueLiteral("Host"), - base.TokValueLiteral(settings.request_host) + base.TokValueLiteral(h) ) ) intermediate = self.__class__(tokens) |