2012-08-16 18:36:30 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2012-08-23 17:27:07 +02:00
|
|
|
# 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.
|
2012-08-16 18:36:30 +02:00
|
|
|
|
|
|
|
import spdylay
|
|
|
|
|
|
|
|
# private key file
|
|
|
|
KEY_FILE='server.key'
|
|
|
|
# certificate file
|
|
|
|
CERT_FILE='server.crt'
|
|
|
|
|
2012-08-23 17:27:07 +02:00
|
|
|
class MySPDYRequestHandler(spdylay.BaseSPDYRequestHandler):
|
2012-08-16 18:36:30 +02:00
|
|
|
|
2012-08-23 17:27:07 +02:00
|
|
|
def do_GET(self):
|
|
|
|
if self.path == '/notfound':
|
2012-08-23 18:25:42 +02:00
|
|
|
# Example code to return error
|
2012-08-23 17:27:07 +02:00
|
|
|
self.send_error(404)
|
|
|
|
return
|
2012-08-17 16:39:48 +02:00
|
|
|
|
2012-08-23 17:27:07 +02:00
|
|
|
self.send_response(200)
|
2012-08-24 14:17:53 +02:00
|
|
|
self.send_header('content-type', 'text/html; charset=UTF-8')
|
2012-08-17 16:39:48 +02:00
|
|
|
|
2012-08-23 17:27:07 +02:00
|
|
|
content = '''\
|
2012-08-16 18:36:30 +02:00
|
|
|
<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>
|
2012-08-23 17:27:07 +02:00
|
|
|
</html>'''.encode('UTF-8')
|
2012-08-22 18:59:21 +02:00
|
|
|
|
2012-08-23 17:27:07 +02:00
|
|
|
self.wfile.write(content)
|
2012-08-16 18:36:30 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
HOST, PORT = "localhost", 3000
|
|
|
|
|
2012-08-23 17:27:07 +02:00
|
|
|
server = spdylay.ThreadedSPDYServer((HOST, PORT),
|
|
|
|
MySPDYRequestHandler,
|
|
|
|
cert_file=CERT_FILE,
|
|
|
|
key_file=KEY_FILE)
|
|
|
|
server.start()
|