Saturday, April 14, 2012

Ubuntu 12.04 Loves Express-Spdy

‹prev | My Chain | next›

I now have express-spdy working with node.js—both the stable 0.6.x release and, as of last night, the unstable 0.7.x series. For both stable and unstable, I have a working express-spdy generator capable of generating and spinning up a SPDY server. The SPDY server has all of the goodness express.js but with working SPDY server push and other SPDY goodness.

My goal for the next couple of weeks is to get the unstable version working with the latest versions of node-spdy (express-spdy currently pegs to last year's version). Last year, I was able to keep things working against node.js unstable with crazy packages with which I polluted npm. This year, I found that I can develop this all on GitHub, provided that I use unstable branches for each of my express.js fork, my connect.js fork, express-spdy, and connect-spdy. Each of those unstable branches has a package.json that lists the other unstable forks as dependencies:
  "author": "Chris Strom  (",
  "name": "express-spdy",
  "description": "SPDY-ize express.js sites.",
  // ...
  "dependencies": {
    "express": "git://",
    "connect-spdy": "git://",
    "spdy": ">= 0.1.0 < 1.0.0",
    "mkdirp": "0.3.0"
  // ...
It is all one, big, happy, very unstable family. But it should be good enough to let me do what I need to do.

But, before moving on, I hope to remove another section from the install instructions for express-spdy. Specifically, installing edge-openssl is a pain. I recently upgraded to Ubuntu 12.04, which is rumored to include a version of openssl that supports NPN (next protocol generation). NPN is how SPDY clients are able to identify servers capable of speaking SPDY. Without it, SPDY will not work.

The current version of node that I have installed is SPDY capable by virtue of linking to the edge-openssl that I have installed locally:
➜  ldd ~/local/node-v0.6.15/bin/node
        ... => /home/chris/local/lib/ (0x00007fc500d59000) => /home/chris/local/lib/ (0x00007fc500990000)
The version of openssl included in Ubuntu 12.04 is 1.0.1-4ubuntu1. Given that my edge-openssl is 1.1.x, this does not look promising. Hopefully NPN simply got backported.

To find out, I configure node,js without the alternate openssl options. That is, I use the default system openssl:
➜  node-v0.6.15  ./configure --prefix=$HOME/local/node-v0.6.15 
Checking for program g++ or c++          : /usr/bin/g++ 
Checking for program cpp                 : /usr/bin/cpp 
Checking for program ar                  : /usr/bin/ar 
Checking for program ranlib              : /usr/bin/ranlib 
Checking for g++                         : ok  
Checking for program gcc or cc           : /usr/bin/gcc 
Checking for gcc                         : ok  
Checking for library dl                  : yes 
Checking for openssl                     : yes 
Checking for library util                : yes 
Checking for library rt                  : yes 
Checking for fdatasync(2) with c++       : yes 
'configure' finished successfully (0.710s)
After installing the system linked node.js, I npm install express-spdy globally (to get the executable generator), run the generator to build a sample server, install the packages necessary for the server, and fire up the server:
➜  repos  npm install -g express-spdy
➜  repos  express-spdy express-spdy-test
➜  repos  cd express-spdy-test
➜  express-spdy-test  npm install
➜  express-spdy-test  node app
Express server listening on port 3000 in development mode
And hitting that server, I get an actual SPDY session (as confirmed by the SPDY tab in chrome://net-internals:
t=1334460160529 [st=    0] +SPDY_SESSION  [dt=11009]
                            --> host = "localhost:3000"
                            --> proxy = "DIRECT"
t=1334460160531 [st=    2]    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
Just to be absolutely sure, I watch the page load with Wireshark and indeed, thar be NPN going on:

That is huge. The instructions for express-spdy just shrank to:
  1. install node.js
  2. install the express-spdy generator
  3. generate the site
  4. install site dependencies
  5. run the server
In the first edition of SPDY Book, it was a three page appendix entry. Yay for progress!

Day #356

No comments:

Post a Comment