diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-04-30 09:46:49 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-04-30 09:46:49 +1200 |
commit | 24b0acbfab0e6fcc65c2fc3ff924a1df3d72fa92 (patch) | |
tree | 82ce39a2d0daa28d432523e9ac0ccd09faedf47a | |
parent | 5d6bd3291edb690a80bcbc8183995343fbd910f4 (diff) | |
download | mitmproxy-24b0acbfab0e6fcc65c2fc3ff924a1df3d72fa92.tar.gz mitmproxy-24b0acbfab0e6fcc65c2fc3ff924a1df3d72fa92.tar.bz2 mitmproxy-24b0acbfab0e6fcc65c2fc3ff924a1df3d72fa92.zip |
Log retrieval API.
-rw-r--r-- | README.mkd | 55 | ||||
-rw-r--r-- | libpathod/app.py | 16 |
2 files changed, 69 insertions, 2 deletions
@@ -201,7 +201,8 @@ a specifier for generating 100 megabytes: @100m -The supported suffixes are: +Data is generated and served efficiently - if you really want to send a +terabyte of data to a client, __pathod__ can do it. The supported suffixes are: b = 1024**0 (bytes) k = 1024**1 (kilobytes) @@ -232,6 +233,58 @@ Supported data types are: ascii bytes +# API + +__pathod__ exposes a simple API, intended to make it possible to drive and +inspect the daemon remotely for use in unit testing and the like. The next +release will include a client-side library that makes this transparent. + +### /api/log + +Returns the current log buffer. At the moment the buffer size is 500 entries - +when the log grows larger than this, older entries are discarded. The returned +data is a JSON dictionary, with the form: + + { + 'logs': [ ENTRIES ] + } + +Where each entry looks like this: + + { + # Record of actions taken at specified byte offsets + 'actions': [(200, 'disconnect'), (10, 'pause', 1)], + # HTTP return code + 'code': 200, + # Request duration in seconds + 'duration': 0.00020599365234375, + # ID unique to this invocation of pathod + 'id': 2, + # The request that triggered the response + 'request': { + 'full_url': 'http://testing:9999/p/200:b@1000:p1,10:d200', + 'headers': { + 'Accept': '*/*', + 'Host': 'localhost:9999', + 'User-Agent': 'curl/7.21.4' + }, + 'host': 'localhost:9999', + 'method': 'POST', + 'path': '/p/200:b@1000:p1,10:d200', + 'protocol': 'http', + 'query': '', + 'remote_address': ('10.0.0.234', 63448), + 'uri': '/p/200:b@1000:p1,10:d200', + 'version': 'HTTP/1.1' + }, + # The response spec that was served. You can re-parse this to get full + # details on the response. + 'spec': '200:b@1000:p1,10:d200', + # Time at which response startd. + 'started': 1335735586.469218 + } + + # Installing diff --git a/libpathod/app.py b/libpathod/app.py index fbb99dc4..7059f9ba 100644 --- a/libpathod/app.py +++ b/libpathod/app.py @@ -2,6 +2,16 @@ import urllib, pprint import tornado.web, tornado.template, tornado.ioloop, tornado.httpserver import rparse, utils + +class APILog(tornado.web.RequestHandler): + def get(self): + self.write( + dict( + d = self.application.get_log() + ) + ) + + class _Page(tornado.web.RequestHandler): def render(self, name, **kwargs): tornado.web.RequestHandler.render(self, name + ".html", **kwargs) @@ -118,6 +128,7 @@ class PathodApp(tornado.web.Application): (r"/log/([0-9]+)", OneLog), (r"/help", Help), (r"/preview", Preview), + (r"/api/log", APILog), (r"/p/.*", RequestPathod, settings), ], static_path = utils.data.path("static"), @@ -179,9 +190,12 @@ class PathodApp(tornado.web.Application): if i["id"] == id: return i - def clear_logs(self): + def clear_log(self): self.log = [] + def get_log(self): + return self.log + # begin nocover def run(application, port, ssl_options): |