mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
Add Path specification to request parser.
This commit is contained in:
parent
f8622ea914
commit
2ac84be7cb
@ -5,6 +5,6 @@
|
|||||||
</h1>
|
</h1>
|
||||||
</div>
|
</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
|
||||||
|
@ -290,6 +290,20 @@ class Body:
|
|||||||
return e.setParseAction(lambda x: klass(*x))
|
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:
|
class Method:
|
||||||
methods = [
|
methods = [
|
||||||
"get",
|
"get",
|
||||||
@ -416,8 +430,10 @@ class Request:
|
|||||||
ShortcutContentType,
|
ShortcutContentType,
|
||||||
)
|
)
|
||||||
version = "HTTP/1.1"
|
version = "HTTP/1.1"
|
||||||
body = LiteralGenerator("")
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.method = None
|
||||||
|
self.path = None
|
||||||
|
self.body = LiteralGenerator("")
|
||||||
self.headers = []
|
self.headers = []
|
||||||
self.actions = []
|
self.actions = []
|
||||||
|
|
||||||
@ -428,6 +444,8 @@ class Request:
|
|||||||
resp = pp.And(
|
resp = pp.And(
|
||||||
[
|
[
|
||||||
Method.expr(),
|
Method.expr(),
|
||||||
|
pp.Literal(":").suppress(),
|
||||||
|
Path.expr(),
|
||||||
pp.ZeroOrMore(pp.Literal(":").suppress() + atom)
|
pp.ZeroOrMore(pp.Literal(":").suppress() + atom)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
@ -88,9 +88,13 @@ class TestMisc:
|
|||||||
assert rparse.Value.parseString('"val"')[0].val == "val"
|
assert rparse.Value.parseString('"val"')[0].val == "val"
|
||||||
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):
|
def test_method(self):
|
||||||
e = rparse.Method.expr()
|
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("'foo'")[0].value.val == "foo"
|
||||||
assert e.parseString("'get'")[0].value.val == "get"
|
assert e.parseString("'get'")[0].value.val == "get"
|
||||||
|
|
||||||
@ -189,9 +193,13 @@ class TestPauses:
|
|||||||
|
|
||||||
|
|
||||||
class TestParseRequest:
|
class TestParseRequest:
|
||||||
|
def test_err(self):
|
||||||
|
tutils.raises(rparse.ParseException, rparse.parse_request, {}, 'GET')
|
||||||
|
|
||||||
def test_simple(self):
|
def test_simple(self):
|
||||||
r = rparse.parse_request({}, "GET")
|
r = rparse.parse_request({}, 'GET:"/foo"')
|
||||||
assert r.method == "GET"
|
assert r.method == "GET"
|
||||||
|
assert r.path == "/foo"
|
||||||
|
|
||||||
|
|
||||||
class TestParseResponse:
|
class TestParseResponse:
|
||||||
|
Loading…
Reference in New Issue
Block a user