diff options
Diffstat (limited to 'libmproxy')
-rw-r--r-- | libmproxy/flow.py | 30 | ||||
-rw-r--r-- | libmproxy/proxy.py | 6 |
2 files changed, 28 insertions, 8 deletions
diff --git a/libmproxy/flow.py b/libmproxy/flow.py index bb9d34f8..549942a5 100644 --- a/libmproxy/flow.py +++ b/libmproxy/flow.py @@ -346,9 +346,10 @@ class Request(HTTPMsg): timestamp: Seconds since the epoch method: HTTP method """ - def __init__(self, client_conn, host, port, scheme, method, path, headers, content, timestamp=None): + def __init__(self, client_conn, httpversion, host, port, scheme, method, path, headers, content, timestamp=None): assert isinstance(headers, ODictCaseless) self.client_conn = client_conn + self.httpversion = httpversion self.host, self.port, self.scheme = host, port, scheme self.method, self.path, self.headers, self.content = method, path, headers, content self.timestamp = timestamp or utils.timestamp() @@ -420,6 +421,7 @@ class Request(HTTPMsg): def _get_state(self): return dict( client_conn = self.client_conn._get_state() if self.client_conn else None, + httpversion = self.httpversion, host = self.host, port = self.port, scheme = self.scheme, @@ -434,6 +436,7 @@ class Request(HTTPMsg): def _from_state(klass, state): return klass( ClientConnect._from_state(state["client_conn"]), + tuple(state["httpversion"]), str(state["host"]), state["port"], str(state["scheme"]), @@ -523,8 +526,8 @@ class Request(HTTPMsg): """ if self.content == CONTENT_MISSING: return None - FMT = '%s %s HTTP/1.1\r\n%s\r\n%s' - FMT_PROXY = '%s %s://%s:%s%s HTTP/1.1\r\n%s\r\n%s' + FMT = '%s %s HTTP/%s.%s\r\n%s\r\n%s' + FMT_PROXY = '%s %s://%s:%s%s HTTP/%s.%s\r\n%s\r\n%s' headers = self.headers.copy() utils.del_all( @@ -547,9 +550,26 @@ class Request(HTTPMsg): if self.close: headers["connection"] = ["close"] if not _proxy: - return FMT % (self.method, self.path, str(headers), content) + return FMT % ( + self.method, + self.path, + self.httpversion[0], + self.httpversion[1], + str(headers), + content + ) else: - return FMT_PROXY % (self.method, self.scheme, self.host, self.port, self.path, str(headers), content) + return FMT_PROXY % ( + self.method, + self.scheme, + self.host, + self.port, + self.path, + self.httpversion[0], + self.httpversion[1], + str(headers), + content + ) def replace(self, pattern, repl, *args, **kwargs): """ diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index 4eeb17c9..c7e5d972 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -465,7 +465,7 @@ class ProxyHandler(SocketServer.StreamRequestHandler): method, path, httpversion = parse_init_http(line) headers = read_headers(self.rfile) content = self.read_contents(client_conn, headers, httpversion) - return flow.Request(client_conn, host, port, "http", method, path, headers, content) + return flow.Request(client_conn, httpversion, host, port, "http", method, path, headers, content) elif line.startswith("CONNECT"): host, port, httpversion = parse_init_connect(line) # FIXME: Discard additional headers sent to the proxy. Should I expose @@ -486,12 +486,12 @@ class ProxyHandler(SocketServer.StreamRequestHandler): method, path, httpversion = parse_init_http(self.rfile.readline(line)) headers = read_headers(self.rfile) content = self.read_contents(client_conn, headers, httpversion) - return flow.Request(client_conn, host, port, "https", method, path, headers, content) + return flow.Request(client_conn, httpversion, host, port, "https", method, path, headers, content) else: method, scheme, host, port, path, httpversion = parse_init_proxy(line) headers = read_headers(self.rfile) content = self.read_contents(client_conn, headers, httpversion) - return flow.Request(client_conn, host, port, scheme, method, path, headers, content) + return flow.Request(client_conn, httpversion, host, port, scheme, method, path, headers, content) def send_response(self, response): d = response._assemble() |