Skip to content

Instantly share code, notes, and snippets.

@JosePedroDias
Created February 20, 2018 00:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JosePedroDias/6c2534afc6be9b725184b892ec3b1eb8 to your computer and use it in GitHub Desktop.
Save JosePedroDias/6c2534afc6be9b725184b892ec3b1eb8 to your computer and use it in GitHub Desktop.
mitmproxy CORS
# 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