diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-06-20 10:51:37 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-06-20 10:51:37 +1200 |
commit | 7922e70037f56d71494cbe0c24fd7536ff76eeee (patch) | |
tree | 12020e2398c0593b9f2b80f8eca64ed5dc214877 /libpathod/pathod.py | |
parent | 892ee2a9041166ca4ae1e35893174791b96cccfa (diff) | |
download | mitmproxy-7922e70037f56d71494cbe0c24fd7536ff76eeee.tar.gz mitmproxy-7922e70037f56d71494cbe0c24fd7536ff76eeee.tar.bz2 mitmproxy-7922e70037f56d71494cbe0c24fd7536ff76eeee.zip |
Basic response generation.
Diffstat (limited to 'libpathod/pathod.py')
-rw-r--r-- | libpathod/pathod.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/libpathod/pathod.py b/libpathod/pathod.py index c8608bd6..9fabc026 100644 --- a/libpathod/pathod.py +++ b/libpathod/pathod.py @@ -1,5 +1,6 @@ +import urllib from netlib import tcp, protocol, odict, wsgi -import version, app +import version, app, rparse class PathodHandler(tcp.BaseHandler): @@ -11,6 +12,19 @@ class PathodHandler(tcp.BaseHandler): return None method, path, httpversion = protocol.parse_init_http(line) + if path.startswith(self.server.prefix): + spec = urllib.unquote(path)[len(self.server.prefix):] + try: + presp = rparse.parse({}, spec) + except rparse.ParseException, v: + presp = rparse.InternalResponse( + 800, + "Error parsing response spec: %s\n"%v.msg + v.marked() + ) + presp.serve(self.wfile) + self.finish() + return + headers = odict.ODictCaseless(protocol.read_headers(self.rfile)) content = protocol.read_http_body_request( self.rfile, self.wfile, headers, httpversion, None @@ -27,10 +41,10 @@ class PathodHandler(tcp.BaseHandler): app.serve(req, self.wfile) - class Pathod(tcp.TCPServer): - def __init__(self, addr): + def __init__(self, addr, prefix="/p/"): tcp.TCPServer.__init__(self, addr) + self.prefix = prefix self.app = app.app self.app.config["pathod"] = self |