Comparing version 0.3.4 to 0.3.5
@@ -17,2 +17,3 @@ const common = require('./common') | ||
var length = 0 | ||
var closed = false | ||
var headArgs = null | ||
@@ -30,2 +31,5 @@ | ||
res.write = function (data) { | ||
var cb = getCallback(arguments) | ||
if (closed) return cb && cb() | ||
if (data) { | ||
@@ -36,3 +40,2 @@ length += +data.length || 0 | ||
var cb = getCallback(arguments) | ||
if (cb) cb() | ||
@@ -42,2 +45,5 @@ } | ||
res.end = function (data) { | ||
var cb = getCallback(arguments) | ||
if (closed) return cb && cb() | ||
if (data && typeof data !== 'function') { | ||
@@ -49,2 +55,19 @@ buf.push(data) | ||
// Expose the body | ||
res.body = res._originalBody = body | ||
// Restore and clean references | ||
cleanupAndRestore() | ||
middleware(req, res, finisher(cb)) | ||
} | ||
req.on('close', onClose) | ||
function onClose() { | ||
closed = true | ||
cleanupAndRestore() | ||
} | ||
function cleanupAndRestore() { | ||
// Restore methods | ||
@@ -55,10 +78,5 @@ res.writeHead = _writeHead | ||
// Expose the body | ||
res.body = res._originalBody = body | ||
// Clean references to prevent leaks | ||
buf = body = _end = _write = headArgs = null | ||
var cb = getCallback(arguments) | ||
middleware(req, res, finisher(cb)) | ||
req.removeListener('close', onClose) | ||
} | ||
@@ -68,2 +86,4 @@ | ||
return function (err, body, encoding) { | ||
if (closed) return cb && cb() | ||
if (err) { | ||
@@ -70,0 +90,0 @@ res.statusCode = +err.status || 500 |
{ | ||
"name": "rocky", | ||
"version": "0.3.4", | ||
"version": "0.3.5", | ||
"description": "Full-featured, middleware-oriented HTTP proxy with traffic replay and intercept", | ||
@@ -5,0 +5,0 @@ "repository": "h2non/rocky", |
const expect = require('chai').expect | ||
const Emitter = require('events').EventEmitter | ||
const middleware = require('../../lib/middleware') | ||
@@ -16,2 +17,6 @@ const noop = function () {} | ||
beforeEach(function () { | ||
req = new Emitter | ||
}) | ||
function middlewareFn(req, res, next) { | ||
@@ -37,3 +42,3 @@ var body = res.body.toString() | ||
(middlewareFn) | ||
(null, res, noop) | ||
(req, res, noop) | ||
@@ -55,3 +60,3 @@ writeData() | ||
(middlewareFn, filter) | ||
(null, res, noop) | ||
(req, res, noop) | ||
@@ -58,0 +63,0 @@ writeData() |
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
140544
3314