aboutsummaryrefslogtreecommitdiffstats
path: root/examples/har_extractor.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2016-07-08 20:11:12 -0700
committerGitHub <noreply@github.com>2016-07-08 20:11:12 -0700
commit15c10d49f6b020c5b913ae5b5e8c4b923a507a47 (patch)
treeb13eb4f3ec88fa90b515edcf4323363124dcd995 /examples/har_extractor.py
parentf7639e077ab10dc8e7f180f44b531b9ad35c060b (diff)
parent5d2b7c52f9c33e84be5c4330b09b0f2a5ad869e2 (diff)
downloadmitmproxy-15c10d49f6b020c5b913ae5b5e8c4b923a507a47.tar.gz
mitmproxy-15c10d49f6b020c5b913ae5b5e8c4b923a507a47.tar.bz2
mitmproxy-15c10d49f6b020c5b913ae5b5e8c4b923a507a47.zip
Merge pull request #1327 from mitmproxy/remove-script-context
Remove script context
Diffstat (limited to 'examples/har_extractor.py')
-rw-r--r--examples/har_extractor.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/examples/har_extractor.py b/examples/har_extractor.py
index a5c05519..2a69b9af 100644
--- a/examples/har_extractor.py
+++ b/examples/har_extractor.py
@@ -2,6 +2,7 @@
This inline script utilizes harparser.HAR from
https://github.com/JustusW/harparser to generate a HAR log object.
"""
+import mitmproxy
import six
import sys
import pytz
@@ -54,7 +55,13 @@ class _HARLog(HAR.log):
return self.__page_list__
-def start(context):
+class Context(object):
+ pass
+
+context = Context()
+
+
+def start():
"""
On start we create a HARLog instance. You will have to adapt this to
suit your actual needs of HAR generation. As it will probably be
@@ -79,7 +86,7 @@ def start(context):
context.seen_server = set()
-def response(context, flow):
+def response(flow):
"""
Called when a server response has been received. At the time of this
message both a request and a response are present and completely done.
@@ -201,7 +208,7 @@ def response(context, flow):
context.HARLog.add(entry)
-def done(context):
+def done():
"""
Called once on script shutdown, after any other events.
"""
@@ -212,17 +219,17 @@ def done(context):
compressed_json_dump = context.HARLog.compress()
if context.dump_file == '-':
- context.log(pprint.pformat(json.loads(json_dump)))
+ mitmproxy.ctx.log(pprint.pformat(json.loads(json_dump)))
elif context.dump_file.endswith('.zhar'):
file(context.dump_file, "w").write(compressed_json_dump)
else:
file(context.dump_file, "w").write(json_dump)
- context.log(
+ mitmproxy.ctx.log(
"HAR log finished with %s bytes (%s bytes compressed)" % (
len(json_dump), len(compressed_json_dump)
)
)
- context.log(
+ mitmproxy.ctx.log(
"Compression rate is %s%%" % str(
100. * len(compressed_json_dump) / len(json_dump)
)