Socket
Socket
Sign inDemoInstall

finalhandler

Package Overview
Dependencies
Maintainers
5
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

finalhandler - npm Package Compare versions

Comparing version 0.0.3 to 0.1.0

7

HISTORY.md

@@ -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)
}
}

5

package.json
{
"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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc