我刚刚浏览了SPDY白皮书,现在很想尝试使用它。 我知道Google正在使用SPDY通过SSL向Chrome提供内容。
如何以最简单的方式设置并通过SPDY提供一个基本的“Hello world” HTML页面呢?
我刚刚浏览了SPDY白皮书,现在很想尝试使用它。 我知道Google正在使用SPDY通过SSL向Chrome提供内容。
如何以最简单的方式设置并通过SPDY提供一个基本的“Hello world” HTML页面呢?
我用C语言编写了spdylay SPDY库,并最近添加了Python包装器python-spdylay。 它需要Python 3.3.0(在撰写本文时为RC1), 但您可以像这样编写简单的SPDY服务器:
#!/usr/bin/env python
import spdylay
# private key file
KEY_FILE='server.key'
# certificate file
CERT_FILE='server.crt'
class MySPDYRequestHandler(spdylay.BaseSPDYRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('content-type', 'text/html; charset=UTF-8')
content = '''\
<html><head><title>SPDY</title></head><body><h1>Hello World</h1>
</body></html>'''.encode('UTF-8')
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()