finalhandler
Advanced tools
Comparing version 0.0.3 to 0.1.0
@@ -0,1 +1,8 @@ | ||
0.1.0 / 2014-07-16 | ||
================== | ||
* Respond after request fully read | ||
- prevents hung responses and socket hang ups | ||
* deps: debug@1.0.4 | ||
0.0.3 / 2014-07-11 | ||
@@ -2,0 +9,0 @@ ================== |
64
index.js
@@ -88,4 +88,21 @@ /*! | ||
send(req, res, res.statusCode, msg) | ||
} | ||
} | ||
/** | ||
* Send response. | ||
* | ||
* @param {IncomingMessage} req | ||
* @param {OutgoingMessage} res | ||
* @param {number} status | ||
* @param {string} body | ||
* @api private | ||
*/ | ||
function send(req, res, status, body) { | ||
function write() { | ||
res.statusCode = status | ||
res.setHeader('Content-Type', 'text/html; charset=utf-8') | ||
res.setHeader('Content-Length', Buffer.byteLength(msg, 'utf8')) | ||
res.setHeader('Content-Length', Buffer.byteLength(body, 'utf8')) | ||
@@ -97,4 +114,47 @@ if (req.method === 'HEAD') { | ||
res.end(msg, 'utf8') | ||
res.end(body, 'utf8') | ||
} | ||
if (!req.readable) { | ||
write() | ||
return | ||
} | ||
// unpipe everything from the request | ||
unpipe(req) | ||
// flush the request | ||
req.once('end', write) | ||
req.resume() | ||
} | ||
/** | ||
* Unpipe everything from a stream. | ||
* | ||
* @param {Object} stream | ||
* @api private | ||
*/ | ||
/* istanbul ignore next: implementation differs between versions */ | ||
function unpipe(stream) { | ||
if (typeof stream.unpipe === 'function') { | ||
// new-style | ||
stream.unpipe() | ||
return | ||
} | ||
// Node.js 0.8 hack | ||
var listener | ||
var listeners = stream.listeners('close') | ||
for (var i = 0; i < listeners.length; i++) { | ||
listener = listeners[i] | ||
if (listener.name !== 'cleanup' && listener.name !== 'onclose') { | ||
continue | ||
} | ||
// invoke the listener | ||
listener.call(stream) | ||
} | ||
} |
{ | ||
"name": "finalhandler", | ||
"description": "Node.js final http responder", | ||
"version": "0.0.3", | ||
"version": "0.1.0", | ||
"author": "Douglas Christopher Wilson <doug@somethingdoug.com>", | ||
@@ -9,3 +9,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"debug": "1.0.3", | ||
"debug": "1.0.4", | ||
"escape-html": "1.0.1" | ||
@@ -16,2 +16,3 @@ }, | ||
"mocha": "~1.20.1", | ||
"readable-stream": "~1.0.27", | ||
"should": "~4.0.1", | ||
@@ -18,0 +19,0 @@ "supertest": "~0.13.0" |
@@ -28,2 +28,4 @@ # finalhandler | ||
The final handler will also unpipe anything from `req` when it is invoked. | ||
#### options.env | ||
@@ -30,0 +32,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8260
127
141
5
+ Addeddebug@1.0.4(transitive)
- Removeddebug@1.0.3(transitive)
Updateddebug@1.0.4