Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gevent
Commits
41d4fdf0
Commit
41d4fdf0
authored
Sep 15, 2010
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix to examples/webproxy.py to be runnable by external WSGI servers
parent
61c768b4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
8 deletions
+18
-8
examples/webproxy.py
examples/webproxy.py
+18
-8
No files found.
examples/webproxy.py
View file @
41d4fdf0
#!/usr/bin/python
#!/usr/bin/env python
"""A web application that retrieves other websites for you.
To start serving the application on port 8088, type
python webproxy.py
To start the server on some other interface/port, use
python -m gevent.wsgi -p 8000 -i 0.0.0.0 webproxy.py
"""
from
gevent
import
monkey
;
monkey
.
patch_all
()
from
gevent
import
wsgi
import
sys
...
...
@@ -9,12 +20,11 @@ from urlparse import urlparse
from
cgi
import
escape
from
urllib
import
unquote
PORT
=
8088
PROXY_URL
=
'http://127.0.0.1:%s/'
%
PORT
def
application
(
env
,
start_response
):
proxy_url
=
'http://%s/'
%
env
[
'HTTP_HOST'
]
method
=
env
[
'REQUEST_METHOD'
]
path
=
env
[
'PATH_INFO'
]
if
env
[
'QUERY_STRING'
]:
...
...
@@ -24,11 +34,11 @@ def application(env, start_response):
start_response
(
'200 OK'
,
[(
'Content-Type'
,
'text/html'
)])
return
[
FORM
]
elif
method
==
'GET'
:
return
proxy
(
path
,
start_response
)
return
proxy
(
path
,
start_response
,
proxy_url
)
elif
(
method
,
path
)
==
(
'POST'
,
''
):
key
,
value
=
env
[
'wsgi.input'
].
read
().
strip
().
split
(
'='
)
assert
key
==
'url'
,
repr
(
key
)
start_response
(
'302 Found'
,
[(
'Location'
,
join
(
PROXY_URL
,
unquote
(
value
)))])
start_response
(
'302 Found'
,
[(
'Location'
,
join
(
proxy_url
,
unquote
(
value
)))])
elif
method
==
'POST'
:
start_response
(
'404 Not Found'
,
[])
else
:
...
...
@@ -36,7 +46,7 @@ def application(env, start_response):
return
[]
def
proxy
(
path
,
start_response
):
def
proxy
(
path
,
start_response
,
proxy_url
):
if
'://'
not
in
path
:
path
=
'http://'
+
path
try
:
...
...
@@ -58,7 +68,7 @@ def proxy(path, start_response):
else
:
start_response
(
'%s %s'
%
(
response
.
code
,
response
.
msg
),
headers
)
data
=
response
.
read
()
data
=
fix_links
(
data
,
PROXY_URL
,
host
)
data
=
fix_links
(
data
,
proxy_url
,
host
)
return
[
data
]
...
...
@@ -105,7 +115,7 @@ FORM = """<html><head>
<tr height=30%><td align=center valign=bottom>Type in URL you want to visit and press Enter</td></tr>
<tr><td align=center valign=top>
<form action=/ method=post>
<input size=80 name=url value="http://www.g
oogle.com
"/>
<input size=80 name=url value="http://www.g
event.org
"/>
</form>
</td></tr>
</table></body></table>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment