A lightweight, per-request customizable HTTP proxy for python.
A lightweight, asynchronous, programmable HTTP proxy for python. Built with Tornado.
#### A simple proxy:
import quickproxy quickproxy.run_proxy(port=8080)
#### A reverse proxy:
This proxy will fetch responses from an AWS s3 bucket with the same ID as the request’s hostname.
- def callback(request):
- request.host = request.host+”.s3-website-us-east-1.amazonaws.com” request.port = 80 return request
Quickproxy exposes just one function:
- methods=[‘GET’, ‘POST’], req_callback=DEFAULT_CALLBACK, resp_callback=DEFAULT_CALLBACK, err_callback=DEFAULT_CALLBACK, start_ioloop=True)
It runs a proxy on the specified port. You can pass the following parameters to configure quickproxy:
### Request callback functions
The request callback should receive a RequestObj and return a RequestObj.
- return requestobj
The RequestObj is a python object with the following attributes that can be modified before it is returned:
### Response callback functions
The response and error callbacks should receive a ResponseObj and return a ResponseObj, similar to the request callback above.
The ResponseObj is a python object with the following attributes that can be modified before it is returned:
code: response code, such as 200 for ‘OK’
headers: the response headers
other headers will be stripped out. By default this includes:
(‘Date’, ‘Cache-Control’, ‘Server’, ‘Content-Type’, ‘Location’)
body: response body as a string
Much of this code was adopted from Senko’s tornado-proxy:
…which is itself based on the code by Bill Janssen posted to: http://groups.google.com/group/python-tornado/msg/7bea08e7a049cf26