aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/protocol
diff options
context:
space:
mode:
authorThomas Kriechbaumer <thomas@kriechbaumer.name>2015-08-02 10:36:18 +0200
committerThomas Kriechbaumer <thomas@kriechbaumer.name>2015-08-02 11:26:33 +0200
commit6cce2f14d7d44f2c13fe478624c921f6e71a2230 (patch)
treeb08370459241cbab2302a8e7b4b7f4dabd331c8f /libmproxy/protocol
parentff1e7e64094185205a09eda71ef3c83a9fbcc75c (diff)
downloadmitmproxy-6cce2f14d7d44f2c13fe478624c921f6e71a2230.tar.gz
mitmproxy-6cce2f14d7d44f2c13fe478624c921f6e71a2230.tar.bz2
mitmproxy-6cce2f14d7d44f2c13fe478624c921f6e71a2230.zip
fix tests
Diffstat (limited to 'libmproxy/protocol')
-rw-r--r--libmproxy/protocol/http.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py
index 1b58f824..4c15c80d 100644
--- a/libmproxy/protocol/http.py
+++ b/libmproxy/protocol/http.py
@@ -243,6 +243,7 @@ class HTTPHandler(ProtocolHandler):
# don't throw an error for disconnects that happen
# before/between requests.
return False
+
self.c.log(
"request",
"debug",
@@ -344,7 +345,6 @@ class HTTPHandler(ProtocolHandler):
raise RuntimeError("Unknown State: %s" % state["state"])
def handle_error(self, error, flow=None):
-
message = repr(error)
message_debug = None
@@ -392,19 +392,25 @@ class HTTPHandler(ProtocolHandler):
if not headers:
headers = odict.ODictCaseless()
+ assert isinstance(headers, odict.ODictCaseless)
+
headers["Server"] = [self.c.config.server_version]
headers["Connection"] = ["close"]
headers["Content-Length"] = [len(body)]
headers["Content-Type"] = ["text/html"]
resp = HTTPResponse(
- (1, 1),
+ (1, 1), # if HTTP/2 is used, this value is ignored anyway
status_code,
- '',
+ response,
headers,
body,
)
- self.c.client_conn.send(self.c.client_conn.protocol.assemble(resp))
+
+ # if no protocol is assigned yet - just assume HTTP/1
+ # TODO: maybe check ALPN and use HTTP/2 if required?
+ protocol = self.c.client_conn.protocol or http1.HTTP1Protocol(self.c.client_conn)
+ self.c.client_conn.send(protocol.assemble(resp))
def process_request(self, flow, request):
"""
@@ -575,7 +581,7 @@ class HTTPHandler(ProtocolHandler):
h = self.c.client_conn.protocol._assemble_response_first_line(flow.response)
self.c.client_conn.send(h + "\r\n")
h = self.c.client_conn.protocol._assemble_response_headers(flow.response, preserve_transfer_encoding=True)
- self.c.client_conn.send(h + "\r\n\r\n")
+ self.c.client_conn.send(h + "\r\n")
chunks = self.c.server_conn.protocol.read_http_body_chunked(
flow.response.headers,
@@ -585,12 +591,15 @@ class HTTPHandler(ProtocolHandler):
False,
4096
)
+
if callable(flow.response.stream):
chunks = flow.response.stream(chunks)
+
for chunk in chunks:
for part in chunk:
self.c.client_conn.wfile.write(part)
self.c.client_conn.wfile.flush()
+
flow.response.timestamp_end = utils.timestamp()
def check_close_connection(self, flow):