
HTTP/HTTPS proxy in a single python script
HTTP/HTTPS proxy in a single python script
This script works on Python 2.7. You need to install OpenSSL to intercept HTTPS connections.
Just run as a script:
$ python proxy2.py
Above command runs the proxy on localhost:8080. Verify it works by typing the below command on another terminal of the same host.
$ http_proxy=localhost:8080 curl http://www.example.com/
proxy2 is made for debugging/testing, so it only accepts connections from localhost.
To use another port, specify the port number as the first argument.
$ python proxy2.py 3128
To intercept HTTPS connections, generate private keys and a private CA certificate:
$ ./setup_https_intercept.sh
Through the proxy, you can access http://proxy2.test/ and install the CA certificate in the browsers.
You can easily customize the proxy and modify the requests/responses or save something to the files. The ProxyRequestHandler class has 3 methods to customize:
By default, only save_handler is implemented which outputs HTTP(S) headers and some useful data to the standard output.