aboutsummaryrefslogtreecommitdiffstats
path: root/libpathod
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-11-16 11:31:04 +1300
committerAldo Cortesi <aldo@nullcube.com>2012-11-16 13:46:42 +1300
commitef9cbe3b25face06f941a9f92aac5c79821e83bf (patch)
treebc744521b2c66d15cb8febd19632fde3cb4281ec /libpathod
parent5d18830f7169fcacac2d23b349a82502bd4171b4 (diff)
downloadmitmproxy-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')
-rw-r--r--libpathod/app.py3
-rw-r--r--libpathod/language.py25
-rw-r--r--libpathod/pathod.py1
-rw-r--r--libpathod/templates/docs_lang.html21
4 files changed, 47 insertions, 3 deletions
diff --git a/libpathod/app.py b/libpathod/app.py
index 1fcfa078..78c0fc4a 100644
--- a/libpathod/app.py
+++ b/libpathod/app.py
@@ -1,6 +1,7 @@
import logging, pprint, cStringIO
from flask import Flask, jsonify, render_template, request, abort, make_response
import version, language, utils
+from netlib import http_uastrings
logging.basicConfig(level="DEBUG")
app = Flask(__name__)
@@ -61,7 +62,7 @@ def docs_pathod():
@app.route('/docs/language')
def docs_language():
- return render("docs_lang.html", True, section="docs")
+ return render("docs_lang.html", True, section="docs", uastrings=http_uastrings.UASTRINGS)
@app.route('/docs/pathoc')
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
)
diff --git a/libpathod/pathod.py b/libpathod/pathod.py
index f327ade4..d52af15b 100644
--- a/libpathod/pathod.py
+++ b/libpathod/pathod.py
@@ -30,7 +30,6 @@ class PathodHandler(tcp.BaseHandler):
if self.server.explain:
crafted = crafted.freeze(self.server.request_settings, None)
- print crafted
response_log = language.serve(crafted, self.wfile, self.server.request_settings, None)
log = dict(
type = "crafted",
diff --git a/libpathod/templates/docs_lang.html b/libpathod/templates/docs_lang.html
index f01d61fb..26672bb2 100644
--- a/libpathod/templates/docs_lang.html
+++ b/libpathod/templates/docs_lang.html
@@ -155,6 +155,27 @@
calculate a Content-Length header if a body is set.
</td>
</tr>
+
+ <tr>
+ <td> u<a href="#valuespec">VALUE</a> <br> uSHORTCUT </td>
+
+ <td>
+
+ Set a User-Agent header on this request. You can
+ specify either a complete <a
+ href="#valuespec">VALUE</a>, or a User-Agent shortcut:
+
+ <table class="table table-condensed">
+ {% for i in uastrings %}
+ <tr>
+ <td><b>{{ i[1] }}</b></td>
+ <td>{{ i[0] }}</td>
+ </tr>
+ {% endfor %}
+ </table>
+
+ </td>
+ </tr>
</tbody>
</table>
</div>