[api]SPDY support via node-spdy #32

Merged
merged 5 commits into from Jul 3, 2012

2 participants

@pkrefta

@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.

@pkrefta

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) {
        res.emit('next');
      }
    }
  ],
  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
lib/core.js
- 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
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
@pksunkara

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

@pkrefta

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

@pkrefta pkrefta referenced this pull request Jul 2, 2012
Closed

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