proxy.py 674 B

123456789101112131415161718192021
  1. # -*- coding:utf-8
  2. import mitmproxy.http
  3. class ProxyForward:
  4. def request(self, flow: mitmproxy.http.HTTPFlow) -> None:
  5. url = flow.request.url_date
  6. if url.startswith("https://eip-portal.qa.mlamp.cn/menura/ui"):
  7. url = url.replace("https://eip-portal.qa.mlamp.cn/menura/ui", "http://127.0.0.1:8500/ui")
  8. flow.request.url_date = url
  9. def response(self, flow: mitmproxy.http.HTTPFlow):
  10. flow.response.headers["test"] = "hhhh"
  11. flow.response.headers["Content-Security-Policy"] = flow.request.host
  12. pass
  13. def error(self, flow: mitmproxy.http.HTTPFlow):
  14. print(flow.error)
  15. addons = [ProxyForward()]