diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2015-05-03 08:56:19 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2015-05-03 08:56:19 +1200 |
commit | bf71a9a2a03697be4332f51727fa19fc4bcb4c62 (patch) | |
tree | b5706847d408445c2bf9fd3edd55c83edde1e493 /libpathod/language/http.py | |
parent | a46e17459d6afa9b9da1e29dd2831c760c8868da (diff) | |
download | mitmproxy-bf71a9a2a03697be4332f51727fa19fc4bcb4c62.tar.gz mitmproxy-bf71a9a2a03697be4332f51727fa19fc4bcb4c62.tar.bz2 mitmproxy-bf71a9a2a03697be4332f51727fa19fc4bcb4c62.zip |
base.PathodSpec -> http.PathodResponse
Diffstat (limited to 'libpathod/language/http.py')
-rw-r--r-- | libpathod/language/http.py | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/libpathod/language/http.py b/libpathod/language/http.py index f926a8cf..2be43fdf 100644 --- a/libpathod/language/http.py +++ b/libpathod/language/http.py @@ -88,6 +88,38 @@ class ShortcutUserAgent(_HeaderMixin, base.OptionsOrValue): ) +class PathodResponse(base.Token): + def __init__(self, value): + self.value = value + try: + self.parsed = Response( + Response.expr().parseString( + value.val, + parseAll=True + ) + ) + except pp.ParseException, v: + raise exceptions.ParseException(v.msg, v.line, v.col) + + @classmethod + def expr(klass): + e = pp.Literal("s").suppress() + e = e + base.ValueLiteral.expr() + return e.setParseAction(lambda x: klass(*x)) + + def values(self, settings): + return [ + self.value.get_generator(settings), + ] + + def spec(self): + return "s%s"%(self.value.spec()) + + def freeze(self, settings): + f = self.parsed.freeze(settings).spec() + return PathodResponse(base.ValueLiteral(f.encode("string_escape"))) + + def get_header(val, headers): """ Header keys may be Values, so we have to "generate" them as we try the @@ -248,7 +280,7 @@ class Request(_HTTPMessage): ShortcutContentType, ShortcutUserAgent, Raw, - base.PathodSpec, + PathodResponse, actions.PauseAt, actions.DisconnectAt, @@ -270,7 +302,7 @@ class Request(_HTTPMessage): @property def pathodspec(self): - return self.tok(base.PathodSpec) + return self.tok(PathodResponse) def preamble(self, settings): v = self.method.values(settings) |