-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathsimple_http2.py
More file actions
executable file
·35 lines (27 loc) · 936 Bytes
/
simple_http2.py
File metadata and controls
executable file
·35 lines (27 loc) · 936 Bytes
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
"""
http://jcalderone.livejournal.com/49707.html
http://labs.twistedmatrix.com/2008/02/simple-python-web-server.html
usage:
$ twistd -y webserver.py
"""
from pprint import pprint
from twisted.application import internet
from twisted.application.service import Application
from twisted.web.resource import Resource
from twisted.web.server import Site
class FormPage(Resource):
def render_GET(self, request):
return 'form'
def render_POST(self, request):
pprint(request.__dict__)
newdata = request.content.getvalue()
print newdata
return ''
class HelloPage(Resource):
def render_GET(self, request):
return "hello"
root = Resource()
root.putChild("form", FormPage())
root.putChild("hello", HelloPage())
application = Application("My Web Service")
internet.TCPServer(10000, Site(root, timeout=60*15)).setServiceParent(application)