Created
April 13, 2015 14:12
-
-
Save jpic/82ff94d64663fddece13 to your computer and use it in GitHub Desktop.
HTTP/HTTPS MITM Proxy to WSGI app
This file contains 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
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