From 9bae97eb17ed66a33b5b988c6857ca6c9fae8e22 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Tue, 18 Aug 2015 13:43:26 +0200 Subject: http2: fix connection preface and wrappers --- libmproxy/protocol2/http.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'libmproxy/protocol2/http.py') diff --git a/libmproxy/protocol2/http.py b/libmproxy/protocol2/http.py index db5aabaf..e73bbb61 100644 --- a/libmproxy/protocol2/http.py +++ b/libmproxy/protocol2/http.py @@ -10,7 +10,7 @@ from libmproxy.protocol import KILL from libmproxy.protocol.http import HTTPFlow from libmproxy.protocol.http_wrappers import HTTPResponse, HTTPRequest from netlib import tcp -from netlib.http import status_codes, http1, HttpErrorConnClosed, HttpError +from netlib.http import status_codes, http1, http2, HttpErrorConnClosed, HttpError from netlib.http.semantics import CONTENT_MISSING from netlib import odict from netlib.tcp import NetLibError, Address @@ -64,6 +64,7 @@ class Http2Layer(Layer): self.server_protocol = HTTP2Protocol(self.server_conn) def __call__(self): + self.server_protocol.perform_connection_preface() layer = HttpLayer(self, self.mode) layer() @@ -166,10 +167,6 @@ class UpstreamConnectLayer(Layer): self.ctx.set_server(address, server_tls, sni, depth-1) class HttpLayer(Layer): - """ - HTTP 1 Layer - """ - def __init__(self, ctx, mode): super(HttpLayer, self).__init__(ctx) self.mode = mode @@ -337,15 +334,18 @@ class HttpLayer(Layer): self.reconnect() get_response() + if isinstance(self.server_protocol, http2.HTTP2Protocol): + flow.response.stream_id = flow.request.stream_id + # call the appropriate script hook - this is an opportunity for an # inline script to set flow.stream = True flow = self.channel.ask("responseheaders", flow) if flow is None or flow == KILL: raise Kill() - if flow.response.stream and isinstance(self.server_protocol, http1.HTTP1Protocol): + if flow.response.stream: flow.response.content = CONTENT_MISSING - else: + elif isinstance(self.server_protocol, http1.HTTP1Protocol): flow.response.content = self.server_protocol.read_http_body( flow.response.headers, self.config.body_size_limit, @@ -466,6 +466,4 @@ class HttpLayer(Layer): self.server_conn.send(self.server_protocol.assemble(message)) def send_to_client(self, message): - # FIXME - # - possibly do some http2 stuff here self.client_conn.send(self.client_protocol.assemble(message)) -- cgit v1.2.3 From 97bfd1d856b26216fffbf84b9e75e49b41fc6fb2 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Wed, 19 Aug 2015 16:36:22 +0200 Subject: move send method to lower layers --- libmproxy/protocol2/http.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'libmproxy/protocol2/http.py') diff --git a/libmproxy/protocol2/http.py b/libmproxy/protocol2/http.py index e73bbb61..b8b1e8a5 100644 --- a/libmproxy/protocol2/http.py +++ b/libmproxy/protocol2/http.py @@ -28,6 +28,12 @@ class Http1Layer(Layer): self.client_protocol = HTTP1Protocol(self.client_conn) self.server_protocol = HTTP1Protocol(self.server_conn) + def send_to_client(self, message): + self.client_conn.send(self.client_protocol.assemble(message)) + + def send_to_server(self, message): + self.server_conn.send(self.server_protocol.assemble(message)) + def connect(self): self.ctx.connect() self.server_protocol = HTTP1Protocol(self.server_conn) @@ -51,6 +57,14 @@ class Http2Layer(Layer): self.client_protocol = HTTP2Protocol(self.client_conn, is_server=True) self.server_protocol = HTTP2Protocol(self.server_conn, is_server=False) + def send_to_client(self, message): + # TODO: implement flow control and WINDOW_UPDATE frames + self.client_conn.send(self.client_protocol.assemble(message)) + + def send_to_server(self, message): + # TODO: implement flow control and WINDOW_UPDATE frames + self.server_conn.send(self.server_protocol.assemble(message)) + def connect(self): self.ctx.connect() self.server_protocol = HTTP2Protocol(self.server_conn) @@ -166,6 +180,7 @@ class UpstreamConnectLayer(Layer): else: self.ctx.set_server(address, server_tls, sni, depth-1) + class HttpLayer(Layer): def __init__(self, ctx, mode): super(HttpLayer, self).__init__(ctx) @@ -461,9 +476,3 @@ class HttpLayer(Layer): odict.ODictCaseless([[k,v] for k, v in self.config.authenticator.auth_challenge_headers().items()]) )) raise InvalidCredentials("Proxy Authentication Required") - - def send_to_server(self, message): - self.server_conn.send(self.server_protocol.assemble(message)) - - def send_to_client(self, message): - self.client_conn.send(self.client_protocol.assemble(message)) -- cgit v1.2.3