-
-
Save jazzyjackson/dfc5c21cfb49df407dd81a24756f9635 to your computer and use it in GitHub Desktop.
mitmproxy CORS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# based on https://gist.github.com/jhass/652dd780d23c1e236ff913e8a2b77eb2 | |
# http://jsbin.com/wonitaqode/edit?js,output | |
# mitmproxy -s cors.py | |
# mitmdump -s cors.py | |
from mitmproxy import http | |
def response(flow): | |
h = flow.request.headers | |
origin = h['origin'] if 'origin' in h else '*' | |
flow.response.headers["Access-Control-Allow-Origin"] = origin | |
#flow.response.headers["Access-Control-Expose-Headers"] = "Authorization" | |
def request(flow): | |
print(flow.request.method, flow.request.url) | |
# print(flow.request.headers) | |
# print(dir(flow.request)) # method host path url pretty_url port pretty_host | |
# print(flow.request.host) | |
# print(flow.request.path) | |
if flow.request.method == "OPTIONS": | |
h = flow.request.headers | |
origin = h['origin'] if 'origin' in h else '*' | |
flow.response = http.HTTPResponse.make(200, b"", | |
{ | |
"Access-Control-Allow-Origin": origin, | |
"Access-Control-Allow-Methods": "GET,POST", | |
"Access-Control-Allow-Headers": "Authorization", | |
"Access-Control-Max-Age": "1728000" | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment