aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-06-24 18:38:22 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-06-24 18:38:22 +1200
commit2ac84be7cb0e4a17fd39c6155074a37161662593 (patch)
treefc66771b1fb313d6aa121484b140adacc9c831b8
parentf8622ea914b506013625c539388349d53b4a7e58 (diff)
downloadmitmproxy-2ac84be7cb0e4a17fd39c6155074a37161662593.tar.gz
mitmproxy-2ac84be7cb0e4a17fd39c6155074a37161662593.tar.bz2
mitmproxy-2ac84be7cb0e4a17fd39c6155074a37161662593.zip
Add Path specification to request parser.
-rw-r--r--doc-src/pathoc.html4
-rw-r--r--libpathod/rparse.py20
-rw-r--r--test/test_rparse.py12
3 files changed, 31 insertions, 5 deletions
diff --git a/doc-src/pathoc.html b/doc-src/pathoc.html
index 6f25e19d..a330343a 100644
--- a/doc-src/pathoc.html
+++ b/doc-src/pathoc.html
@@ -5,6 +5,6 @@
</h1>
</div>
-pathoc hostname get:/foo/bar:h"foo"="bar" get:/wah:b@1m
+pathoc hostname get:"/foo/bar":h"foo"="bar" get:/wah:b@1m
-pathoc --ssl hostname get:/foo/bar:h"foo"="bar" get:/wah:b@1m
+pathoc --ssl hostname get:"/foo/bar":h"foo"="bar" get:"/wah":b@1m
diff --git a/libpathod/rparse.py b/libpathod/rparse.py
index 50ae9804..af0f9671 100644
--- a/libpathod/rparse.py
+++ b/libpathod/rparse.py
@@ -290,6 +290,20 @@ class Body:
return e.setParseAction(lambda x: klass(*x))
+class Path:
+ def __init__(self, value):
+ self.value = value
+
+ def accept(self, settings, r):
+ r.path = self.value.get_generator(settings)
+
+ @classmethod
+ def expr(klass):
+ e = Value.copy()
+ return e.setParseAction(lambda x: klass(*x))
+
+
+
class Method:
methods = [
"get",
@@ -416,8 +430,10 @@ class Request:
ShortcutContentType,
)
version = "HTTP/1.1"
- body = LiteralGenerator("")
def __init__(self):
+ self.method = None
+ self.path = None
+ self.body = LiteralGenerator("")
self.headers = []
self.actions = []
@@ -428,6 +444,8 @@ class Request:
resp = pp.And(
[
Method.expr(),
+ pp.Literal(":").suppress(),
+ Path.expr(),
pp.ZeroOrMore(pp.Literal(":").suppress() + atom)
]
)
diff --git a/test/test_rparse.py b/test/test_rparse.py
index 2a76c3e8..5761d84a 100644
--- a/test/test_rparse.py
+++ b/test/test_rparse.py
@@ -88,9 +88,13 @@ class TestMisc:
assert rparse.Value.parseString('"val"')[0].val == "val"
assert rparse.Value.parseString('"\'val\'"')[0].val == "'val'"
+ def test_path(self):
+ e = rparse.Path.expr()
+ assert e.parseString('"/foo"')[0].value.val == "/foo"
+
def test_method(self):
e = rparse.Method.expr()
- assert e.parseString("get")[0].value == "GET"
+ assert e.parseString("get")[0].value.val == "GET"
assert e.parseString("'foo'")[0].value.val == "foo"
assert e.parseString("'get'")[0].value.val == "get"
@@ -189,9 +193,13 @@ class TestPauses:
class TestParseRequest:
+ def test_err(self):
+ tutils.raises(rparse.ParseException, rparse.parse_request, {}, 'GET')
+
def test_simple(self):
- r = rparse.parse_request({}, "GET")
+ r = rparse.parse_request({}, 'GET:"/foo"')
assert r.method == "GET"
+ assert r.path == "/foo"
class TestParseResponse: