nghttp2/python/spdyserv.py

44 lines
1.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python
# The example SPDY server. Python 3.3 or later is required because TLS
# NPN is used in spdylay.ThreadedSPDYServer. Put private key and
# certificate file in the current working directory.
import spdylay
# private key file
KEY_FILE='server.key'
# certificate file
CERT_FILE='server.crt'
class MySPDYRequestHandler(spdylay.BaseSPDYRequestHandler):
def do_GET(self):
if self.path == '/notfound':
2012-08-23 18:25:42 +02:00
# Example code to return error
self.send_error(404)
return
self.send_response(200)
2012-08-24 14:17:53 +02:00
self.send_header('content-type', 'text/html; charset=UTF-8')
content = '''\
<html>
<head><title>SPDY FTW</title></head>
<body>
<h1>SPDY FTW</h1>
<p>The age of HTTP/1.1 is over. The time of SPDY has come.</p>
</body>
</html>'''.encode('UTF-8')
2012-08-22 18:59:21 +02:00
self.wfile.write(content)
if __name__ == "__main__":
HOST, PORT = "localhost", 3000
server = spdylay.ThreadedSPDYServer((HOST, PORT),
MySPDYRequestHandler,
cert_file=CERT_FILE,
key_file=KEY_FILE)
server.start()