diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-11-16 11:31:04 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-11-16 13:46:42 +1300 |
commit | ef9cbe3b25face06f941a9f92aac5c79821e83bf (patch) | |
tree | bc744521b2c66d15cb8febd19632fde3cb4281ec /libpathod/language.py | |
parent | 5d18830f7169fcacac2d23b349a82502bd4171b4 (diff) | |
download | mitmproxy-ef9cbe3b25face06f941a9f92aac5c79821e83bf.tar.gz mitmproxy-ef9cbe3b25face06f941a9f92aac5c79821e83bf.tar.bz2 mitmproxy-ef9cbe3b25face06f941a9f92aac5c79821e83bf.zip |
Add u User-agent shortcut.
Usage:
200:ua - Shortcut "a" for Android.
200:u"foo" - Or a value literal
Shortcuts can be listed using the --show-uas argument to pathoc.
Diffstat (limited to 'libpathod/language.py')
-rw-r--r-- | libpathod/language.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/libpathod/language.py b/libpathod/language.py index 79657b37..30788569 100644 --- a/libpathod/language.py +++ b/libpathod/language.py @@ -2,7 +2,7 @@ import operator, string, random, mmap, os, time, copy import abc from email.utils import formatdate import contrib.pyparsing as pp -from netlib import http_status, tcp +from netlib import http_status, tcp, http_uastrings import utils @@ -449,6 +449,28 @@ class ShortcutLocation(_Header): return ShortcutLocation(self.value.freeze(settings)) +class ShortcutUserAgent(_Header): + def __init__(self, value): + self.specvalue = value + if isinstance(value, basestring): + value = ValueLiteral(http_uastrings.get_by_shortcut(value)[2]) + _Header.__init__(self, ValueLiteral("User-Agent"), value) + + @classmethod + def expr(klass): + e = pp.Literal("u").suppress() + u = reduce(operator.or_, [pp.Literal(i[1]) for i in http_uastrings.UASTRINGS]) + e += u | Value + return e.setParseAction(lambda x: klass(*x)) + + def spec(self): + return "u%s"%self.specvalue + + def freeze(self, settings): + return ShortcutUserAgent(self.value.freeze(settings)) + + + class Body(_Component): def __init__(self, value): self.value = value @@ -824,6 +846,7 @@ class Response(_Message): InjectAt, ShortcutContentType, ShortcutLocation, + ShortcutUserAgent, Raw, Reason ) |