我正在尝试使用内联脚本和 mitmdump 解析请求和响应标头的不同元素。某些功能未记录在案。我将发布经验教训来回答这个问题。
问问题
692 次
2 回答
2
为什么不使用官方文档?
http://mitmproxy.org/doc/scripting/inlinescripts.html
规范的 API 文档是代码,您可以在本地或在我们的 GitHub 存储库中浏览。您可以使用 pydoc(默认与 Python 一起安装)查看 API 文档,如下所示:
pydoc libmproxy.protocol.http.HTTPRequest
提供更好的输出。
于 2015-04-19T01:34:27.107 回答
0
在内联脚本中使用 dir() 会显示可用于解析的所有变量。
def response(context, flow):
print dir(flow)
print dir(flow.request)
for cookie in flow.response.headers["Set-Cookie"]:
print "%s:\t%s" % (flow.request.host, cookie)
dir(flow) 的结果
['__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__getattribute__', '__hash__',
'__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__',
'__str__', '__subclasshook__', '__weakref__', '_backup', '_stateobject_attributes',
'_stateobject_long_attributes', 'accept_intercept', 'backup', 'client_conn', 'copy', 'error', 'from_state',
'get_state', 'id', 'intercept', 'intercepting', 'kill', 'live', 'load_state', 'match', 'modified', 'replace',
'reply', 'request', 'response', 'revert', 'server_conn', 'type']
dir(flow.request) 的结果
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__',
'__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
'__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_assemble_first_line', '_assemble_head',
'_assemble_headers', '_stateobject_attributes', '_stateobject_long_attributes', 'anticache', 'anticomp',
'assemble', 'constrain_encoding', 'content', 'copy', 'decode', 'encode', 'form_in', 'form_out', 'from_state',
'from_stream', 'get_cookies', 'get_decoded_content', 'get_form_urlencoded', 'get_path_components',
'get_query', 'get_state', 'headers', 'host', 'httpversion', 'is_replay', 'load_state', 'method', 'path',
'port', 'pretty_host', 'pretty_url', 'replace', 'scheme', 'set_form_urlencoded', 'set_path_components',
'set_query', 'size', 'stickyauth', 'stickycookie', 'timestamp_end', 'timestamp_start', 'update_host_header',
'url']
dir(flow.response) 的结果
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__',
'__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__',
'__str__', '__subclasshook__', '__weakref__', '_assemble_first_line', '_assemble_head', '_assemble_headers',
'_refresh_cookie', '_stateobject_attributes', '_stateobject_long_attributes', 'assemble', 'code', 'content',
'copy', 'decode', 'encode', 'from_state', 'from_stream', 'get_cookies', 'get_decoded_content', 'get_state',
'headers', 'httpversion', 'is_replay', 'load_state', 'msg', 'refresh', 'replace', 'size', 'stream',
'timestamp_end', 'timestamp_start']
于 2015-04-18T19:27:58.053 回答