Comparing version 1.0.0 to 1.1.0
@@ -231,3 +231,3 @@ var framer = exports; | ||
connection.write(header); | ||
stream.write(header); | ||
}; |
@@ -60,4 +60,3 @@ var parser = exports; | ||
while (this.waiting > offset && this.buffered >= this.waiting && | ||
sliced < this.buffer.length) { | ||
while (this.waiting > offset && sliced < this.buffer.length) { | ||
var chunk = this.buffer[sliced++], | ||
@@ -64,0 +63,0 @@ overmatched = false; |
@@ -8,55 +8,71 @@ var spdy = require('../spdy'), | ||
// | ||
// ### function Server (options, requestListener) | ||
// #### @options {Object} tls server options | ||
// #### @requestListener {Function} (optional) request callback | ||
// SPDY Server @constructor | ||
// ### function instantiate (HTTPSServer) | ||
// #### @HTTPSServer {https.Server|Function} Base server class | ||
// Will return constructor for SPDY Server, based on the HTTPSServer class | ||
// | ||
function Server(options, requestListener) { | ||
options || (options = {}); | ||
options.NPNProtocols = ['spdy/2', 'http/1.1', 'http/1.0'] | ||
function instantiate(HTTPSServer) { | ||
// | ||
// ### function Server (options, requestListener) | ||
// #### @options {Object} tls server options | ||
// #### @requestListener {Function} (optional) request callback | ||
// SPDY Server @constructor | ||
// | ||
function Server(options, requestListener) { | ||
options || (options = {}); | ||
options.NPNProtocols = ['spdy/2', 'http/1.1', 'http/1.0'] | ||
https.Server.call(this, options, requestListener); | ||
HTTPSServer.call(this, options, requestListener); | ||
// Use https if NPN is not supported | ||
if (!process.features.tls_npn && !options.debug) return; | ||
// Use https if NPN is not supported | ||
if (!process.features.tls_npn && !options.debug) return; | ||
// Wrap connection handler | ||
var self = this, | ||
connectionHandler = this.listeners('secureConnection')[0]; | ||
// Wrap connection handler | ||
var self = this, | ||
connectionHandler = this.listeners('secureConnection')[0]; | ||
this.removeAllListeners('secureConnection'); | ||
this.on('secureConnection', function secureConnection(socket) { | ||
// Fallback to HTTPS if needed | ||
if (socket.npnProtocol !== 'spdy/2' && !options.debug) { | ||
return connectionHandler.call(this, socket); | ||
} | ||
this.removeAllListeners('secureConnection'); | ||
this.on('secureConnection', function secureConnection(socket) { | ||
// Fallback to HTTPS if needed | ||
if (socket.npnProtocol !== 'spdy/2' && !options.debug) { | ||
return connectionHandler.call(this, socket); | ||
} | ||
// Wrap incoming socket into abstract class | ||
var connection = new Connection(socket); | ||
// Wrap incoming socket into abstract class | ||
var connection = new Connection(socket); | ||
// Emulate each stream like connection | ||
connection.on('stream', connectionHandler); | ||
// Emulate each stream like connection | ||
connection.on('stream', connectionHandler); | ||
connection.on('request', function(req, res) { | ||
res.writeHead = spdy.response.writeHead; | ||
req.streamID = req.socket.id; | ||
connection.on('request', function(req, res) { | ||
res.writeHead = spdy.response.writeHead; | ||
req.streamID = req.socket.id; | ||
req.isSpdy = true; | ||
res.on('finish', function() { | ||
req.connection.end(); | ||
res.on('finish', function() { | ||
req.connection.end(); | ||
}); | ||
self.emit('request', req, res); | ||
}); | ||
self.emit('request', req, res); | ||
}); | ||
connection.on('error', function(e) { | ||
socket.destroy(e); | ||
connection.on('error', function(e) { | ||
socket.destroy(e); | ||
}); | ||
// Send SETTINGS frame (MAX_CONCURRENT_STREAMS = 100) | ||
connection.write(spdy.utils.settings); | ||
}); | ||
} | ||
util.inherits(Server, HTTPSServer); | ||
// Send SETTINGS frame (MAX_CONCURRENT_STREAMS = 100) | ||
connection.write(spdy.utils.settings); | ||
}); | ||
} | ||
util.inherits(Server, https.Server); | ||
return Server; | ||
}; | ||
exports.instantiate = instantiate; | ||
// Export Server instantiated from https.Server | ||
var Server = instantiate(https.Server); | ||
exports.Server = Server; | ||
// | ||
// ### function create (options, requestListener) | ||
// ### function create (base, options, requestListener) | ||
// #### @base {Function} (optional) base server class (https.Server) | ||
// #### @options {Object} tls server options | ||
@@ -66,4 +82,15 @@ // #### @requestListener {Function} (optional) request callback | ||
// | ||
exports.create = function create(options, requestListener) { | ||
return new Server(options, requestListener); | ||
exports.create = function create(base, options, requestListener) { | ||
var server; | ||
if (typeof base === 'function') { | ||
server = instantiate(base); | ||
} else { | ||
server = Server; | ||
requestListener = options; | ||
options = base; | ||
base = null; | ||
} | ||
return new server(options, requestListener); | ||
}; | ||
@@ -118,3 +145,3 @@ | ||
if (frame.data.length > 0){ | ||
if (stream.halfClosed) { | ||
if (stream.closedBy.client) { | ||
stream.rstCode = 2; | ||
@@ -152,8 +179,8 @@ stream.emit('error', 'Writing to half-closed stream'); | ||
// Don't allow to close stream twice | ||
if (stream.halfClosed) { | ||
if (stream.closedBy.client) { | ||
stream.rstCode = 2; | ||
stream.emit('error', 'Already half-closed'); | ||
} else { | ||
stream.halfClosed = true; | ||
stream.emit('end'); | ||
stream.closedBy.client = true; | ||
stream.handleClose(); | ||
} | ||
@@ -172,2 +199,3 @@ } | ||
util.inherits(Connection, process.EventEmitter); | ||
exports.Connection = Connection; | ||
@@ -220,2 +248,7 @@ // | ||
this.closedBy = { | ||
client: false, | ||
server: false | ||
}; | ||
// Lock data | ||
@@ -241,2 +274,3 @@ this.locked = false; | ||
util.inherits(Stream, stream.Stream); | ||
exports.Stream = Stream; | ||
@@ -263,4 +297,3 @@ // | ||
this.ondata(req, 0, req.length); | ||
this.emit('data', req); | ||
this._read(req); | ||
}; | ||
@@ -302,2 +335,12 @@ | ||
// | ||
// ### function handleClose () | ||
// Close stream if it was closed by both server and client | ||
// | ||
Stream.prototype.handleClose = function handleClose() { | ||
if (this.closedBy.client && this.closedBy.server) { | ||
this.close(); | ||
} | ||
}; | ||
// | ||
// ### function close () | ||
@@ -321,6 +364,12 @@ // Destroys stream | ||
this.connection.streamsCount--; | ||
if (error) { | ||
if (this.rstCode) spdy.framer.sendRst(this, this.rstCode); | ||
this.emit('error', error); | ||
} | ||
var self = this; | ||
process.nextTick(function() { | ||
if (error) self.emit('error', error); | ||
self.emit('close'); | ||
}); | ||
}; | ||
@@ -353,2 +402,4 @@ | ||
spdy.framer.sendData(this, true, new Buffer(0)); | ||
this.closedBy.server = true; | ||
this.handleClose(); | ||
}; | ||
@@ -373,8 +424,12 @@ | ||
var self = this; | ||
this._buffer.forEach(function(chunk) { | ||
self.ondata && self.ondata(chunk, 0, chunk.length); | ||
self.emit('data', chunk); | ||
var self = this, | ||
buffer = this._buffer; | ||
this._buffer = []; | ||
process.nextTick(function() { | ||
buffer.forEach(function(chunk) { | ||
self._read(chunk); | ||
}); | ||
}); | ||
this._buffer = []; | ||
}; | ||
@@ -393,4 +448,7 @@ | ||
this.ondata && this.ondata(data, 0, data.length); | ||
this.emit('data', data); | ||
var self = this; | ||
process.nextTick(function() { | ||
self.ondata && self.ondata(data, 0, data.length); | ||
self.emit('data', data); | ||
}); | ||
}; |
{ | ||
"name": "spdy", | ||
"version": "1.1.0", | ||
"description": "Implementation of the SPDY protocol on node.js.", | ||
"version": "1.0.0", | ||
"keywords": [ | ||
"spdy" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/indutny/node-spdy.git" | ||
}, | ||
"homepage": "https://github.com/indutny/node-spdy", | ||
"bugs": { | ||
"email": "node-spdy+bugs@indutny.com", | ||
"url": "https://github.com/indunty/node-spdy/issues" | ||
}, | ||
"author": "Fedor Indutny <fedor.indutny@gmail.com>", | ||
@@ -11,7 +23,12 @@ "contributors": [ | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"mocha": "0.8.x" | ||
}, | ||
"scripts": { | ||
"test": "mocha --ui tdd --growl --reporter spec test/unit/*-test.js" | ||
}, | ||
"engines": [ | ||
"node ~ 0.7.0" | ||
], | ||
"main": "./lib/spdy", | ||
"devDependencies": {} | ||
"main": "./lib/spdy" | ||
} |
@@ -1,2 +0,2 @@ | ||
# SPDY Server for node.js | ||
# SPDY Server for node.js [![Build Status](https://secure.travis-ci.org/indutny/node-spdy.png)](http://travis-ci.org/indutny/node-spdy) | ||
@@ -63,3 +63,3 @@ With this module you can create [SPDY](http://www.chromium.org/spdy) servers | ||
Copyright Fedor Indutny, 2011. | ||
Copyright Fedor Indutny, 2012. | ||
@@ -84,2 +84,1 @@ Permission is hereby granted, free of charge, to any person obtaining a | ||
USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
30
2048
0
2
5
198456
1
83