File: httpserver.py

package info (click to toggle)
python-gevent 0.13.6-1%2Bnmu3
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 2,324 kB
  • sloc: python: 13,296; makefile: 95; ansic: 37
file content (20 lines) | stat: -rwxr-xr-x 609 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/python
"""HTTP server example.

Uses libevent API directly and thus may be dangerous.
WSGI interface is a safer choice, see examples/wsgiserver.py.
"""
from gevent import http


def callback(request):
    print request
    if request.uri == '/':
        request.add_output_header('Content-Type', 'text/html')
        request.send_reply(200, "OK", '<b>hello world</b>')
    else:
        request.add_output_header('Content-Type', 'text/html')
        request.send_reply(404, "Not Found", "<h1>Not Found</h1>")

print 'Serving on 8088...'
http.HTTPServer(('0.0.0.0', 8088), callback).serve_forever()