Skip to content

Instantly share code, notes, and snippets.

@kostyll
Created July 10, 2016 08:39
Show Gist options
  • Select an option

  • Save kostyll/a0098b1d80e8e68a48d0a30017856048 to your computer and use it in GitHub Desktop.

Select an option

Save kostyll/a0098b1d80e8e68a48d0a30017856048 to your computer and use it in GitHub Desktop.
# 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)
@kostyll
Copy link
Copy Markdown
Author

kostyll commented Jul 10, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment