aboutsummaryrefslogtreecommitdiffstats
path: root/libpathod
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-04-28 22:51:36 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-04-28 22:51:36 +1200
commit2d989e2fbb8b87847c215a984bc8a010ce583a8e (patch)
tree88086af48ff1836d27c25334584be04f4e342127 /libpathod
parent5052a6d34efb008399860950318efc69eddf5b42 (diff)
downloadmitmproxy-2d989e2fbb8b87847c215a984bc8a010ce583a8e.tar.gz
mitmproxy-2d989e2fbb8b87847c215a984bc8a010ce583a8e.tar.bz2
mitmproxy-2d989e2fbb8b87847c215a984bc8a010ce583a8e.zip
Add a shortcut for setting content-type.
Diffstat (limited to 'libpathod')
-rw-r--r--libpathod/__init__.py1
-rw-r--r--libpathod/rparse.py23
2 files changed, 22 insertions, 2 deletions
diff --git a/libpathod/__init__.py b/libpathod/__init__.py
index 4ef52a84..ff1b88f8 100644
--- a/libpathod/__init__.py
+++ b/libpathod/__init__.py
@@ -19,4 +19,3 @@ def application(**settings):
static_path = utils.data.path("static"),
template_path = utils.data.path("templates"),
)
-
diff --git a/libpathod/rparse.py b/libpathod/rparse.py
index 62f48d78..4f7cc12d 100644
--- a/libpathod/rparse.py
+++ b/libpathod/rparse.py
@@ -192,6 +192,25 @@ Value = pp.MatchFirst(
)
+class ShortcutContentType:
+ def __init__(self, value):
+ self.value = value
+
+ def mod_response(self, settings, r):
+ r.headers.append(
+ (
+ LiteralGenerator("Content-Type"),
+ self.value.get_generator(settings)
+ )
+ )
+
+ @classmethod
+ def expr(klass):
+ e = pp.Literal("c").suppress()
+ e = e + Value
+ return e.setParseAction(lambda x: klass(*x))
+
+
class Body:
def __init__(self, value):
self.value = value
@@ -240,7 +259,6 @@ class PauseRandom(_Pause):
r.actions.append(("random", "pause", self.value))
-
class _Disconnect:
def __init__(self, value):
self.value = value
@@ -313,6 +331,7 @@ class Response:
PauseRandom,
DisconnectBefore,
DisconnectRandom,
+ ShortcutContentType,
)
version = "HTTP/1.1"
code = 200
@@ -364,8 +383,10 @@ class Response:
def add_timeout(self, s, callback):
if TESTING:
callback()
+ # begin nocover
else:
tornado.ioloop.IOLoop.instance().add_timeout(time.time() + s, callback)
+ # end nocover
def write_values(self, fp, vals, actions, sofar=0, skip=0, blocksize=BLOCKSIZE):
while vals: