aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libpathod/rparse.py21
-rw-r--r--test/test_rparse.py7
2 files changed, 25 insertions, 3 deletions
diff --git a/libpathod/rparse.py b/libpathod/rparse.py
index 4f7cc12d..b47681cc 100644
--- a/libpathod/rparse.py
+++ b/libpathod/rparse.py
@@ -211,6 +211,26 @@ class ShortcutContentType:
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:
def __init__(self, value):
self.value = value
@@ -332,6 +352,7 @@ class Response:
DisconnectBefore,
DisconnectRandom,
ShortcutContentType,
+ ShortcutLocation,
)
version = "HTTP/1.1"
code = 200
diff --git a/test/test_rparse.py b/test/test_rparse.py
index 5a3cb53c..c854b0c6 100644
--- a/test/test_rparse.py
+++ b/test/test_rparse.py
@@ -177,9 +177,10 @@ class uDisconnects(libpry.AutoTree):
assert isinstance(v, rparse.DisconnectRandom)
-class uShortcutContentType(libpry.AutoTree):
+class uShortcuts(libpry.AutoTree):
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):
@@ -312,5 +313,5 @@ tests = [
uDisconnects(),
uMisc(),
uparse(),
- uShortcutContentType()
+ uShortcuts()
]