-
Notifications
You must be signed in to change notification settings - Fork 6
/
example.py
48 lines (31 loc) · 947 Bytes
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import quickproxy
import os
import shlex
import subprocess
'''
A simple example of how to use quickproxy. To try it, first start up the http
server like so:
> python example.py httpserv &
Then you can startup the proxy like this:
> python example.py &
Finally test it with a request:
> curl localhost:8080
Your request to the proxy running on port 8080 will be fetched from the http
server on 4040 according to the request modifications applied in the callback.
To shut down the servers just run `fg` and ^C twice.
'''
def main():
def callback(response):
response.port = 4040
return response
quickproxy.run_proxy(port=8080, req_callback=callback)
def httpserv():
cmd = "python -m SimpleHTTPServer %d" % 4040
cwd = os.path.dirname(os.path.realpath(__file__))+"/tests"
subprocess.call(shlex.split(cmd), cwd=cwd)
if __name__=='__main__':
import sys
if len(sys.argv) > 1:
globals()[sys.argv[1]]()
else:
main()