[api]SPDY support via node-spdy #32

merged 5 commits into from Jul 3, 2012

2 participants


@indutny's node-spdy module is compatible with standard http/https interface so implementation was fairly simple and required changes only in core.createServer method. Because SPDY requires SSL we need to pass the same parameters as we pass into https but with a different option key - spdy instead of https. If client's browser doesn't support SPDY it will nicely degrade to https.
I didn't write any tests because I don't know any standard method to detect SPDY on server - if necessary I can add some additional header to response and write a simple test.


Simple code how to use it

var union = require('./lib'),
    director = require('director');

var router = new director.http.Router();

var server = union.createServer({
  before: [
    function (req, res) {
      var found = router.dispatch(req, res);
      if (!found) {
  spdy :{
    key: '../certs/privatekey.pem',
    cert: '../certs/certificate.pem'

router.get(/foo/, function () {
  this.res.writeHead(200, { 'Content-Type': 'text/plain' })
  this.res.end('hello world\n');

server.listen(9090, function(){
  console.log('union with director running on 9090 with SPDY');
@pksunkara pksunkara commented on an outdated diff Jul 2, 2012
- if (!options.https.key || !options.https.cert) {
- throw new Error('Both `options.https.key` and `options.https.cert` are required.');
+ //
+ // both https and spdy requires same params
+ //
+ if (options.https || options.spdy) {
+ var key;
+ if(options.spdy) {
+ key = 'spdy';
+ } else {
+ key = 'https';
+ }
+ server_options = options[key];
pksunkara added a line comment Jul 2, 2012
  • Memory leak, you didn't declare server_options
  • We don't use underscore in variable names. Use camelized names. serverOptions

Otherwise, lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

And can you write the above example in examples folder and document the SPDY usage in README.md too?


Yes of course - I'll provide fixes (forgotten var :/), examples and docs.

@pkrefta pkrefta referenced this pull request Jul 2, 2012

SPDY support #31

@pksunkara pksunkara merged commit 942cc6d into flatiron:master Jul 3, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment