Skip to content

Instantly share code, notes, and snippets.

@jpic
Created April 13, 2015 14:12
Show Gist options
  • Save jpic/82ff94d64663fddece13 to your computer and use it in GitHub Desktop.
Save jpic/82ff94d64663fddece13 to your computer and use it in GitHub Desktop.
HTTP/HTTPS MITM Proxy to WSGI app
from libmproxy.flow import AppRegistry, version
from netlib import wsgi
import requests
def catchall(environ, start_response):
"""Simplest possible application object"""
data = 'Hello, World!\n'
status = '200 OK'
response_headers = [
('Content-type','text/plain'),
('Content-Length', str(len(data)))
]
start_response(status, response_headers)
return iter([data])
class MyAppRegistry(AppRegistry):
def get(self, request):
app = AppRegistry.get(self, request)
if app:
return app
host = request.headers.get('Host')[0]
return wsgi.WSGIAdaptor(catchall, host, request.port,
version.NAMEVERSION)
def start(context, argv):
context.log("start")
context._master.apps = MyAppRegistry()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment