aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/protocol2/root_context.py
diff options
context:
space:
mode:
authorThomas Kriechbaumer <thomas@kriechbaumer.name>2015-08-16 15:19:11 +0200
committerThomas Kriechbaumer <thomas@kriechbaumer.name>2015-08-16 15:19:11 +0200
commit38c456bb627c4570e0ed983229ec8ef2f120a4b6 (patch)
tree2119fb74f6f4884b2e7edd91322ac09d3b6cd7e3 /libmproxy/protocol2/root_context.py
parentc04fa1b233224d28e85be34ab5b6a8718497488c (diff)
downloadmitmproxy-38c456bb627c4570e0ed983229ec8ef2f120a4b6.tar.gz
mitmproxy-38c456bb627c4570e0ed983229ec8ef2f120a4b6.tar.bz2
mitmproxy-38c456bb627c4570e0ed983229ec8ef2f120a4b6.zip
implement Http1 and Http2 protocols as layers
Diffstat (limited to 'libmproxy/protocol2/root_context.py')
-rw-r--r--libmproxy/protocol2/root_context.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/libmproxy/protocol2/root_context.py b/libmproxy/protocol2/root_context.py
index bda8b12b..a68560c2 100644
--- a/libmproxy/protocol2/root_context.py
+++ b/libmproxy/protocol2/root_context.py
@@ -2,7 +2,7 @@ from __future__ import (absolute_import, print_function, division)
from .rawtcp import RawTcpLayer
from .tls import TlsLayer
-from .http import HttpLayer
+from .http import Http1Layer, Http2Layer, HttpLayer
class RootContext(object):
"""
@@ -34,13 +34,20 @@ class RootContext(object):
d[2] in ('\x00', '\x01', '\x02', '\x03')
)
+ # TODO: build is_http2_magic check here, maybe this is an easy way to detect h2c
+
if not d:
return
if is_tls_client_hello:
return TlsLayer(top_layer, True, True)
- elif isinstance(top_layer, TlsLayer) and isinstance(top_layer.ctx, HttpLayer):
- return HttpLayer(top_layer, "transparent")
+ elif isinstance(top_layer, TlsLayer):
+ if top_layer.client_conn.get_alpn_proto_negotiated() == 'h2':
+ return Http2Layer(top_layer, 'regular') # TODO: regular correct here?
+ else:
+ return Http1Layer(top_layer, 'regular') # TODO: regular correct here?
+ elif isinstance(top_layer, TlsLayer) and isinstance(top_layer.ctx, Http1Layer):
+ return Http1Layer(top_layer, "transparent")
else:
return RawTcpLayer(top_layer)