Created
July 10, 2016 08:39
-
-
Save kostyll/a0098b1d80e8e68a48d0a30017856048 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # Usage: mitmproxy -s maven_stub.py | |
| # (this script works best with --anticache) | |
| # this script was tested on mitmproxy 18 | |
| # MAIN GOAL to help Inteliji idea to get file from inet. | |
| # TO make maven in idea work through our proxy see this url: | |
| # http://stackoverflow.com/questions/1784132/intellij-community-cant-use-http-proxy-for-maven | |
| import sys | |
| from mitmproxy.models import decoded | |
| def log(msg): | |
| with open("log.txt", "a+") as f: | |
| f.write("%s\n" % msg) | |
| log("Strated") | |
| def request(flow): | |
| log("new request:") | |
| log(flow.request.path) | |
| log(flow.request.url) | |
| try: | |
| if "http://repo.maven.apache.org/" in flow.request.url: | |
| fn = "nexus-maven-repository-index.gz" | |
| if fn in flow.request.path: | |
| from mitmproxy.models import HTTPResponse | |
| from netlib.http import Headers | |
| log("is it!!!") | |
| data = open("../%s" % fn, "rb").read() | |
| resp = HTTPResponse( | |
| b"HTTP/1.1", 200, b"OK", | |
| Headers(Content_Type="application/x-gzip"), | |
| data | |
| ) | |
| log(dir(flow.reply)) | |
| flow.reply.send(resp) | |
| except Exception, e: | |
| log(e) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://stackoverflow.com/questions/1784132/intellij-community-cant-use-http-proxy-for-maven