Comparing version 0.3.11 to 0.3.12
@@ -28,2 +28,3 @@ const toxy = require('..') | ||
// Randomly reply with an error | ||
.outgoingPoison(function (req, res) { | ||
@@ -33,2 +34,3 @@ res.writeHead(400, { 'Content-Length': 5 }) | ||
}) | ||
.withRule(rules.method('POST')) | ||
.withRule(rules.probability(75)) | ||
@@ -35,0 +37,0 @@ .withRule(rules.responseHeaders({ 'Content-Type': /json/i })) |
@@ -6,3 +6,3 @@ const isRegExp = require('./is-regexp') | ||
const rule = headers[key] | ||
const value = httpObj.headers[key.toLowerCase()] | ||
const value = (httpObj.headers || httpObj._headers || {})[key.toLowerCase()] | ||
@@ -9,0 +9,0 @@ if (typeof rule === 'boolean') { |
@@ -8,5 +8,2 @@ module.exports = function slowClose (opts) { | ||
const proto = Object.getPrototypeOf(res) | ||
var _end = proto.end | ||
var _setHeader = proto.setHeader | ||
var _writeHead = proto.writeHead | ||
@@ -18,3 +15,3 @@ // Store state | ||
if (header.toLowerCase() !== 'content-length') { | ||
_setHeader.call(res, header, value) | ||
proto.setHeader.call(res, header, value) | ||
} | ||
@@ -27,3 +24,3 @@ } | ||
} | ||
_writeHead.call(res, code, headers) | ||
proto.writeHead.call(res, code, headers) | ||
} | ||
@@ -40,5 +37,5 @@ | ||
// Restore native methods | ||
res.end = _end | ||
res.writeHead = _writeHead | ||
res.setHeaders = _setHeader | ||
res.end = proto.end | ||
res.writeHead = proto.writeHead | ||
res.setHeader = proto.setHeader | ||
@@ -49,4 +46,3 @@ // Ends the response | ||
// Clean references to prevent leaks | ||
_end = _setHeader = null | ||
_writeHead = args = null | ||
args = null | ||
} | ||
@@ -53,0 +49,0 @@ } |
@@ -10,5 +10,4 @@ const helpers = require('../helpers') | ||
return function throttle (req, res, next) { | ||
const proto = Object.getPrototypeOf(res) | ||
var _end = proto.end | ||
var _write = proto.write | ||
var _end = res.end | ||
var _write = res.write | ||
@@ -27,2 +26,3 @@ // Cache payload | ||
if (done) done() | ||
return true | ||
} | ||
@@ -40,3 +40,3 @@ | ||
cleanup() | ||
res.end(done) | ||
try { res.end(done) } catch (e) {} | ||
} | ||
@@ -46,8 +46,6 @@ } | ||
function writeDefer (chunk, next) { | ||
setTimeout(write, delay) | ||
function write () { | ||
setTimeout(function write () { | ||
if (closed) return next('closed') | ||
_write.call(res, chunk.buffer, chunk.encoding, next) | ||
} | ||
}, delay) | ||
} | ||
@@ -54,0 +52,0 @@ |
{ | ||
"name": "toxy", | ||
"version": "0.3.11", | ||
"version": "0.3.12", | ||
"description": "Hackable HTTP proxy to simulate server failure scenarios and network conditions", | ||
@@ -45,3 +45,3 @@ "repository": "h2non/toxy", | ||
"raw-body": "^2.1.2", | ||
"rocky": "^0.4.10", | ||
"rocky": "^0.4.12", | ||
"router": "^1.1.3" | ||
@@ -56,3 +56,3 @@ }, | ||
"standard": "^5.4.1", | ||
"supertest": "^1.0.1" | ||
"supertest": "^1.2.0" | ||
}, | ||
@@ -59,0 +59,0 @@ "standard": { |
@@ -44,2 +44,3 @@ const http = require('http') | ||
const reqStub = { socket: {}, once: function () {} } | ||
const resStub = { connection: { cork: function () {} } } | ||
@@ -67,7 +68,7 @@ proxy.poison(function delay (req, res, next) { | ||
proxy._inPoisons.run(reqStub, {}, function () { | ||
proxy._inPoisons.run(reqStub, resStub, function () { | ||
expect(spy.calledOnce).to.be.true | ||
}) | ||
proxy._outPoisons.run(reqStub, {}, function () { | ||
proxy._outPoisons.run(reqStub, resStub, function () { | ||
expect(spy.calledTwice).to.be.true | ||
@@ -221,3 +222,2 @@ | ||
}) | ||
proxy.outgoingPoison(function capture (req, res, next) { | ||
@@ -301,4 +301,8 @@ spy(req, res) | ||
const server = http.createServer(function (req, res) { | ||
res.writeHead(code, { 'Content-Type': 'application/json' }) | ||
res.write(JSON.stringify({ 'hello': 'world' })) | ||
const data = JSON.stringify({ 'hello': 'world' }) | ||
res.writeHead(code, { | ||
'Content-Length': Buffer.byteLength(data), | ||
'Content-Type': 'application/json' | ||
}) | ||
res.write(data) | ||
@@ -305,0 +309,0 @@ var body = '' |
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
164947
3960
Updatedrocky@^0.4.12