mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 10:26:23 +00:00
Add a shortcut for setting Location header.
This commit is contained in:
parent
2d989e2fbb
commit
ee909e265b
@ -211,6 +211,26 @@ class ShortcutContentType:
|
|||||||
return e.setParseAction(lambda x: klass(*x))
|
return e.setParseAction(lambda x: klass(*x))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class ShortcutLocation:
|
||||||
|
def __init__(self, value):
|
||||||
|
self.value = value
|
||||||
|
|
||||||
|
def mod_response(self, settings, r):
|
||||||
|
r.headers.append(
|
||||||
|
(
|
||||||
|
LiteralGenerator("Location"),
|
||||||
|
self.value.get_generator(settings)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def expr(klass):
|
||||||
|
e = pp.Literal("l").suppress()
|
||||||
|
e = e + Value
|
||||||
|
return e.setParseAction(lambda x: klass(*x))
|
||||||
|
|
||||||
|
|
||||||
class Body:
|
class Body:
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
self.value = value
|
self.value = value
|
||||||
@ -332,6 +352,7 @@ class Response:
|
|||||||
DisconnectBefore,
|
DisconnectBefore,
|
||||||
DisconnectRandom,
|
DisconnectRandom,
|
||||||
ShortcutContentType,
|
ShortcutContentType,
|
||||||
|
ShortcutLocation,
|
||||||
)
|
)
|
||||||
version = "HTTP/1.1"
|
version = "HTTP/1.1"
|
||||||
code = 200
|
code = 200
|
||||||
|
@ -177,9 +177,10 @@ class uDisconnects(libpry.AutoTree):
|
|||||||
assert isinstance(v, rparse.DisconnectRandom)
|
assert isinstance(v, rparse.DisconnectRandom)
|
||||||
|
|
||||||
|
|
||||||
class uShortcutContentType(libpry.AutoTree):
|
class uShortcuts(libpry.AutoTree):
|
||||||
def test_parse(self):
|
def test_parse(self):
|
||||||
assert len(rparse.parse({}, "400:c'foo'").headers) == 1
|
assert rparse.parse({}, "400:c'foo'").headers[0][0][:] == "Content-Type"
|
||||||
|
assert rparse.parse({}, "400:l'foo'").headers[0][0][:] == "Location"
|
||||||
|
|
||||||
|
|
||||||
class uPauses(libpry.AutoTree):
|
class uPauses(libpry.AutoTree):
|
||||||
@ -312,5 +313,5 @@ tests = [
|
|||||||
uDisconnects(),
|
uDisconnects(),
|
||||||
uMisc(),
|
uMisc(),
|
||||||
uparse(),
|
uparse(),
|
||||||
uShortcutContentType()
|
uShortcuts()
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user