Saturday, May 19, 2012

Sample Node-Spdy Sites (from The SPDY Book)

‹prev | My Chain | next›

I am nearly done with my exploration of SPDY flow control. New in version 3 of the protocol, flow control has proven tough to pin down, but I think I have a good handle on it.

One loose end is a more realistic example of a web page. I had that last year and it turns out that some readers of The SPDY Book want to play with that code. So why not kill two birds with one stone?

I git init a new repository and copy over the express-spdy code. One change that I need is to edit the package.json. The following should allow someone with a recent stable node.js (i.e. node.js 0.6.x) to npm install and then run the server:
{
    "name": "spdy-sample"
  , "version": "0.0.1"
  , "private": true
  , "dependencies": {
      "express-spdy": "0.1.3"
    , "jade": ">= 0.0.1"
  }
}
So, I try it :
➜  spdy-sample git:(master) ✗ npm install
...
jade@0.26.0 ./node_modules/jade
├── commander@0.5.2
└── mkdirp@0.3.0

express-spdy@0.1.3 ./node_modules/express-spdy
├── mkdirp@0.3.0
├── express@2.5.9 (qs@0.4.2, mime@1.2.4, connect@1.8.7)
├── connect-spdy@0.1.2 (connect@1.8.7)
└── spdy@0.1.4 (zlibcontext@1.0.9)
➜  spdy-sample git:(master) ✗ node app
Express server listening on port 3000
Nice!

Loading the page up in the browser, I see a super cool SPDY page:


The SPDY tab in chrome://net-internal verifies not only that this is SPDY (version 2), but also that SPDY server push still works:
SPDY_SESSION_SYN_STREAM
--> flags = 1
--> accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    accept-charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
    accept-encoding: gzip,deflate,sdch
    accept-language: en-US,en;q=0.8
    cache-control: no-cache
    cookie: [value was stripped]
    host: localhost:3000
    method: GET
    pragma: no-cache
    referer: https://localhost:3000/
    scheme: https
    url: /real
    user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.11 Safari/536.11
    version: HTTP/1.1
--> id = 1
SPDY_SESSION_SYN_REPLY
--> flags = 0
--> connection: keep-alive
    content-length: 3316
    content-type: text/html
    status: 200 OK
    version: HTTP/1.1
    x-powered-by: Express
--> id = 1
SPDY_SESSION_PUSHED_SYN_STREAM
--> associated_stream = 1
--> flags = 2
--> last-modified: Sun, 20 May 2012 03:11:40 GMT
    status: 200
    url: https://localhost:3000/stylesheets/style.css
    version: http/1.1
--> id = 2
....
SPDY_STREAM_ADOPTED_PUSH_STREAM
SPDY_STREAM_ADOPTED_PUSH_STREAM
SPDY_STREAM_ADOPTED_PUSH_STREAM
SPDY_STREAM_ADOPTED_PUSH_STREAM
SPDY_STREAM_ADOPTED_PUSH_STREAM
SPDY_STREAM_ADOPTED_PUSH_STREAM
SPDY_STREAM_ADOPTED_PUSH_STREAM
SPDY_STREAM_ADOPTED_PUSH_STREAM
SPDY_STREAM_ADOPTED_PUSH_STREAM
SPDY_STREAM_ADOPTED_PUSH_STREAM
SPDY_STREAM_ADOPTED_PUSH_STREAM
SPDY_STREAM_ADOPTED_PUSH_STREAM
SPDY_STREAM_ADOPTED_PUSH_STREAM
...
The SPDY_STREAM_ADOPTED_PUSH_STREAM is important—unless you see that, something went wrong with SPDY push.

I add a README and the sample app is ready on GitHub. For good measure, I add a separate spdy-v3 branch as well.

Hopefully this will prove useful to folks.


Day #391

No comments:

Post a Comment