Skip to content

Commit

Permalink
Optionally encode response bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed Mar 5, 2024
1 parent bdc5b58 commit 20d402f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tests/mitmproxy_addons/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,21 @@ def response(self, flow):
if self.config["callback_url"] == "":
return # ignore responses if we aren't told a url
if flowfilter.match(self.filter, flow):
try:
try: # e.g GET requests have no req body
req_body = flow.request.json()
except:
req_body = None
try: # e.g OPTIONS responses have no res body
res_body = flow.response.json()
except:
res_body = None
data = json.dumps({
"method": flow.request.method,
"access_token": flow.request.headers.get("Authorization", "").removeprefix("Bearer "),
"url": flow.request.url,
"response_code": flow.response.status_code,
"request_body": req_body,
"response_body": flow.response.json(),
"response_body": res_body,
})
request = Request(
self.config["callback_url"],
Expand Down

0 comments on commit 20d402f

Please sign in to comment.