aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-10-04 10:33:57 +1100
committerAldo Cortesi <aldo@nullcube.com>2016-10-04 10:33:57 +1100
commit2bd868662937b504cccd825e9e24e3cb6a142708 (patch)
tree0d111125733f9211f170f345f506738bf4ba6804 /mitmproxy
parent2e48b60ff1f3271ad689ad8bc97f11b4b81ef241 (diff)
downloadmitmproxy-2bd868662937b504cccd825e9e24e3cb6a142708.tar.gz
mitmproxy-2bd868662937b504cccd825e9e24e3cb6a142708.tar.bz2
mitmproxy-2bd868662937b504cccd825e9e24e3cb6a142708.zip
http2: support the requestheaders event
We do this by splitting read_request into read_request_headers and read_request_body.
Diffstat (limited to 'mitmproxy')
-rw-r--r--mitmproxy/controller.py3
-rw-r--r--mitmproxy/protocol/http2.py27
-rw-r--r--mitmproxy/proxy/root_context.py1
3 files changed, 17 insertions, 14 deletions
diff --git a/mitmproxy/controller.py b/mitmproxy/controller.py
index 7996eb46..51a9b146 100644
--- a/mitmproxy/controller.py
+++ b/mitmproxy/controller.py
@@ -90,10 +90,11 @@ class Master(object):
mitmproxy_ctx.master = None
mitmproxy_ctx.log = None
- def add_log(self, e, level="info"):
+ def add_log(self, e, level):
"""
level: debug, info, warn, error
"""
+ pass
def add_server(self, server):
# We give a Channel to the server which can be used to communicate with the master
diff --git a/mitmproxy/protocol/http2.py b/mitmproxy/protocol/http2.py
index 1595fb61..ae12406f 100644
--- a/mitmproxy/protocol/http2.py
+++ b/mitmproxy/protocol/http2.py
@@ -162,6 +162,7 @@ class Http2Layer(base.Layer):
self.streams[eid].priority_weight = event.priority_updated.weight
self.streams[eid].handled_priority_event = event.priority_updated
self.streams[eid].start()
+ self.streams[eid].request_arrived.set()
return True
def _handle_response_received(self, eid, event):
@@ -248,6 +249,7 @@ class Http2Layer(base.Layer):
self.streams[event.pushed_stream_id].pushed = True
self.streams[event.pushed_stream_id].parent_stream_id = parent_eid
self.streams[event.pushed_stream_id].timestamp_end = time.time()
+ self.streams[event.pushed_stream_id].request_arrived.set()
self.streams[event.pushed_stream_id].request_data_finished.set()
self.streams[event.pushed_stream_id].start()
return True
@@ -376,6 +378,7 @@ class Http2SingleStreamLayer(http._HttpTransmissionLayer, basethread.BaseThread)
self.timestamp_start = None
self.timestamp_end = None
+ self.request_arrived = threading.Event()
self.request_data_queue = queue.Queue()
self.request_queued_data_length = 0
self.request_data_finished = threading.Event()
@@ -396,6 +399,7 @@ class Http2SingleStreamLayer(http._HttpTransmissionLayer, basethread.BaseThread)
if not self.zombie:
self.zombie = time.time()
self.request_data_finished.set()
+ self.request_arrived.set()
self.response_arrived.set()
self.response_data_finished.set()
@@ -446,16 +450,10 @@ class Http2SingleStreamLayer(http._HttpTransmissionLayer, basethread.BaseThread)
raise exceptions.Http2ZombieException("Connection already dead")
@detect_zombie_stream
- def read_request(self):
- self.request_data_finished.wait()
-
- data = []
- while self.request_data_queue.qsize() > 0:
- data.append(self.request_data_queue.get())
- data = b"".join(data)
-
+ def read_request_headers(self):
+ self.request_arrived.wait()
+ self.raise_zombie()
first_line_format, method, scheme, host, port, path = http2.parse_headers(self.request_headers)
-
return models.HTTPRequest(
first_line_format,
method,
@@ -465,13 +463,18 @@ class Http2SingleStreamLayer(http._HttpTransmissionLayer, basethread.BaseThread)
path,
b"HTTP/2.0",
self.request_headers,
- data,
+ None,
timestamp_start=self.timestamp_start,
timestamp_end=self.timestamp_end,
)
- def read_request_body(self, request): # pragma: no cover
- raise NotImplementedError()
+ @detect_zombie_stream
+ def read_request_body(self, request):
+ self.request_data_finished.wait()
+ data = []
+ while self.request_data_queue.qsize() > 0:
+ data.append(self.request_data_queue.get())
+ return data
@detect_zombie_stream
def send_request(self, message):
diff --git a/mitmproxy/proxy/root_context.py b/mitmproxy/proxy/root_context.py
index 000ebb13..9827ef74 100644
--- a/mitmproxy/proxy/root_context.py
+++ b/mitmproxy/proxy/root_context.py
@@ -112,7 +112,6 @@ class RootContext(object):
"""
Send a log message to the master.
"""
-
full_msg = [
"{}: {}".format(repr(self.client_conn.address), msg)
]