aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/flow.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-06-10 10:46:22 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-06-10 10:46:22 +1200
commit55ddf853cd8cac13bb6021ef92d21af85cb9b2f1 (patch)
treeb1c15c915076c80a27eaa97d3027c4a13c9fbeb8 /libmproxy/flow.py
parenta3b47e0cb59205fd2512e96ae9058e371c8a5760 (diff)
downloadmitmproxy-55ddf853cd8cac13bb6021ef92d21af85cb9b2f1.tar.gz
mitmproxy-55ddf853cd8cac13bb6021ef92d21af85cb9b2f1.tar.bz2
mitmproxy-55ddf853cd8cac13bb6021ef92d21af85cb9b2f1.zip
Add HTTP version to flow.Request
This is a serialization format change, that makes us incompatible with previous versions.
Diffstat (limited to 'libmproxy/flow.py')
-rw-r--r--libmproxy/flow.py30
1 files changed, 25 insertions, 5 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):
"""