diff options
author | Thomas Kriechbaumer <thomas@kriechbaumer.name> | 2015-07-29 11:26:10 +0200 |
---|---|---|
committer | Thomas Kriechbaumer <thomas@kriechbaumer.name> | 2015-07-30 19:42:48 +0200 |
commit | 31dbd2fc7595d709e41523f3586dfdc02feb07dd (patch) | |
tree | e21889f43750cb979424dcd928510c7bd94efacb /libpathod | |
parent | d301f55bb7df5d4f8156153a36fd600c04b77115 (diff) | |
download | mitmproxy-31dbd2fc7595d709e41523f3586dfdc02feb07dd.tar.gz mitmproxy-31dbd2fc7595d709e41523f3586dfdc02feb07dd.tar.bz2 mitmproxy-31dbd2fc7595d709e41523f3586dfdc02feb07dd.zip |
use netlib http semantics
Diffstat (limited to 'libpathod')
-rw-r--r-- | libpathod/language/http.py | 3 | ||||
-rw-r--r-- | libpathod/language/http2.py | 34 | ||||
-rw-r--r-- | libpathod/protocols/http2.py | 4 |
3 files changed, 30 insertions, 11 deletions
diff --git a/libpathod/language/http.py b/libpathod/language/http.py index 380a5d64..2e8d2af3 100644 --- a/libpathod/language/http.py +++ b/libpathod/language/http.py @@ -7,6 +7,9 @@ import netlib.websockets from netlib.http import status_codes, user_agents from . import base, exceptions, actions, message +# TODO: use netlib.semantics.protocol assemble method, +# instead of duplicating the HTTP on-the-wire representation here. +# see http2 language for an example class WS(base.CaselessLiteral): TOK = "ws" diff --git a/libpathod/language/http2.py b/libpathod/language/http2.py index 8aee9931..8a82fc99 100644 --- a/libpathod/language/http2.py +++ b/libpathod/language/http2.py @@ -1,6 +1,7 @@ import pyparsing as pp -from netlib.http import user_agents +from netlib import odict +from netlib.http import user_agents, semantics from . import base, message """ @@ -155,7 +156,7 @@ class Response(_HTTP2Message): def __init__(self, tokens): super(Response, self).__init__(tokens) self.rendered_values = None - self.stream_id = 0 + self.stream_id = 2 @property def code(self): @@ -178,17 +179,22 @@ class Response(_HTTP2Message): if self.rendered_values: return self.rendered_values else: - headers = [header.values(settings) for header in self.headers] + headers = odict.ODictCaseless([header.values(settings) for header in self.headers]) body = self.body if body: body = body.string() - self.rendered_values = settings.protocol.create_response( + resp = semantics.Response( + (2, 0), self.code.string(), - self.stream_id, + '', headers, - body) + body, + ) + resp.stream_id = self.stream_id + + self.rendered_values = settings.protocol.assemble(resp) return self.rendered_values def spec(self): @@ -215,6 +221,7 @@ class Request(_HTTP2Message): def __init__(self, tokens): super(Request, self).__init__(tokens) self.rendered_values = None + self.stream_id = 1 @property def method(self): @@ -255,17 +262,26 @@ class Request(_HTTP2Message): if self.nested_response: path += self.nested_response.parsed.spec() - headers = [header.values(settings) for header in self.headers] + headers = odict.ODictCaseless([header.values(settings) for header in self.headers]) body = self.body if body: body = body.string() - self.rendered_values = settings.protocol.create_request( + req = semantics.Request( + '', self.method.string(), + '', + '', + '', path, + (2, 0), headers, - body) + body, + ) + req.stream_id = self.stream_id + + self.rendered_values = settings.protocol.assemble(req) return self.rendered_values def spec(self): diff --git a/libpathod/protocols/http2.py b/libpathod/protocols/http2.py index 82ec5482..f57f56f8 100644 --- a/libpathod/protocols/http2.py +++ b/libpathod/protocols/http2.py @@ -16,5 +16,5 @@ class HTTP2Protocol: self.wire_protocol.perform_server_connection_preface() return self.wire_protocol.read_request() - def create_response(self, code, stream_id, headers, body): - return self.wire_protocol.create_response(code, stream_id, headers, body) + def assemble(self, message): + return self.wire_protocol.assemble(message) |