aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Kriechbaumer <thomas@kriechbaumer.name>2015-07-29 11:26:10 +0200
committerThomas Kriechbaumer <thomas@kriechbaumer.name>2015-07-30 19:42:48 +0200
commit31dbd2fc7595d709e41523f3586dfdc02feb07dd (patch)
treee21889f43750cb979424dcd928510c7bd94efacb
parentd301f55bb7df5d4f8156153a36fd600c04b77115 (diff)
downloadmitmproxy-31dbd2fc7595d709e41523f3586dfdc02feb07dd.tar.gz
mitmproxy-31dbd2fc7595d709e41523f3586dfdc02feb07dd.tar.bz2
mitmproxy-31dbd2fc7595d709e41523f3586dfdc02feb07dd.zip
use netlib http semantics
-rw-r--r--libpathod/language/http.py3
-rw-r--r--libpathod/language/http2.py34
-rw-r--r--libpathod/protocols/http2.py4
-rw-r--r--test/test_pathoc.py2
-rw-r--r--test/test_pathod.py2
5 files changed, 32 insertions, 13 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)
diff --git a/test/test_pathoc.py b/test/test_pathoc.py
index 56671109..54590174 100644
--- a/test/test_pathoc.py
+++ b/test/test_pathoc.py
@@ -301,4 +301,4 @@ class TestDaemonHTTP2(_TestDaemon):
)
c.connect()
resp = c.request("get:/p/200")
- assert resp.status_code == "200"
+ assert resp.status_code == 200
diff --git a/test/test_pathod.py b/test/test_pathod.py
index 1f127586..c25de41f 100644
--- a/test/test_pathod.py
+++ b/test/test_pathod.py
@@ -284,4 +284,4 @@ class TestHTTP2(tutils.DaemonTests):
def test_http2(self):
r, _ = self.pathoc(["GET:/"], ssl=True, use_http2=True)
- assert r[0].status_code == "800"
+ assert r[0].status_code == 800