Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #32 from pkrefta/spdy_support

[api]SPDY support via node-spdy
  • Loading branch information...
commit 942cc6dbdedb8cd67e915840ab0aa55c49902d97 2 parents a1f0145 + b9c7c06
@pksunkara pksunkara authored
Showing with 74 additions and 18 deletions.
  1. +12 −10 README.md
  2. +30 −0 examples/simple/spdy.js
  3. +32 −8 lib/core.js
View
22 README.md
@@ -30,14 +30,12 @@ In addition, the response object passed to middlewares listens for a "next" even
``` js
var fs = require('fs'),
union = require('../lib'),
- director = require('director'),
- favicon = require('./middleware/favicon');
+ director = require('director');
var router = new director.http.Router();
var server = union.createServer({
before: [
- favicon('./favicon.png'),
function (req, res) {
var found = router.dispatch(req, res);
if (!found) {
@@ -116,6 +114,8 @@ var server = union.createServer({
}).listen(3000);
```
+### SPDY enabled server example
+
# API
## union Static Members
@@ -149,6 +149,10 @@ Specification
(optional) A value that specifies the certificate and key necessary to create an instance of
`https.Server`.
+ @option spdy {Object}
+ (optional) A value that specifies the certificate and key necessary to create an instance of
+ `spdy.Server`.
+
@option headers {Object}
(optional) An object representing a set of headers to set in every outgoing response
```
@@ -169,15 +173,13 @@ var server = union.createServer({
});
```
-An example of the `https` option.
+An example of the `https` or `spdy` option.
``` js
{
- https: {
- cert: 'path/to/cert.pem',
- key: 'path/to/key.pem',
- ca: 'path/to/ca.pem'
- }
+ cert: 'path/to/cert.pem',
+ key: 'path/to/key.pem',
+ ca: 'path/to/ca.pem'
}
```
@@ -310,7 +312,7 @@ All tests are written with [vows][0] and should be run with [npm][1]:
(The MIT License)
-Copyright (c) 2010 Nodejitsu Inc. <http://www.twitter.com/nodejitsu>
+Copyright (c) 2010-2012 Nodejitsu Inc. <http://www.twitter.com/nodejitsu>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
View
30 examples/simple/spdy.js
@@ -0,0 +1,30 @@
+// In order to run this example you need to
+// generate local ssl certificate
+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');
+});
View
40 lib/core.js
@@ -1,5 +1,5 @@
/*
- * core.js: Core functionality for the Flatiron HTTP plugin.
+ * core.js: Core functionality for the Flatiron HTTP (with SPDY support) plugin.
*
* (C) 2011, Nodejitsu Inc.
* MIT LICENSE
@@ -50,18 +50,42 @@ core.createServer = function (options) {
req.pipe(routingStream);
}
- if (options.https) {
- 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) {
+
+ if(options.https && options.spdy){
+ throw new Error('You shouldn\'t be using https and spdy simultaneously.')
+ }
+
+ var key, serverOptions, credentials;
+
+ if(options.spdy) {
+ key = 'spdy';
+ } else {
+ key = 'https';
+ }
+
+ serverOptions = options[key];
+
+ if (!serverOptions.key || !serverOptions.cert) {
+ throw new Error('Both options.'+key+'.`key` and options.'+key+'.`cert` are required.');
}
credentials = {
- key: fs.readFileSync(options.https.key),
- cert: fs.readFileSync(options.https.cert)
+ key: fs.readFileSync(serverOptions.key),
+ cert: fs.readFileSync(serverOptions.cert)
};
- if (options.https.ca) {
- credentials.ca = fs.readFileSync(options.https.ca);
+ if (serverOptions.ca) {
+ credentials.ca = fs.readFileSync(serverOptions.ca);
+ }
+
+ if(options.spdy){
+ // spdy is optional so we require module here rather than on top
+ var spdy = require('spdy');
+ return spdy.createServer(credentials, requestHandler);
}
return https.createServer(credentials, requestHandler);
Please sign in to comment.
Something went wrong with that request. Please try again.