开发者

What would a SPDY "Hello world" look like?

I just finished skimming the SPDY white paper and now I'm interested in 开发者_JAVA百科trying it out. I understand that Google is serving content over SSL to Chrome using SPDY.

What's the easiest way to set up and serve a basic "Hello world" HTML page over SPDY?


Run an existing spdy server such as:

https://github.com/indutny/node-spdy


It would seem that the quickest and easiest way would be to follow the instructions located here.


I wrote spdylay SPDY library in C and recently added Python wrapper python-spdylay. It needs Python 3.3.0 (which is RC1 at the time of this writing), but you can write simple SPDY server just like this:

#!/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()


The intention of SPDY is that it is entirely transparent to your webapplication. You don't need to write code to use SPDY, you just need to use a webserver that supports it.

If you have a java web application, then you can SPDY enable it by using Jetty. 3 simple steps: add a jar to the boot path to enable NPN, create an SSL certificate for your server, configure SPDY as the connector type. See http://wiki.eclipse.org/Jetty/Feature/SPDY

This will be even easier in Jetty-9

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜