diff --git a/index.js b/index.js index a3a45224..effeea6c 100644 --- a/index.js +++ b/index.js @@ -62,11 +62,6 @@ module.exports = function compression(options) { , compress = true , stream; - // see #8 - req.on('close', function(){ - res.write = res.end = function(){}; - }); - // flush is noop by default res.flush = noop; diff --git a/test/test.js b/test/test.js index 7e804a05..fb0df126 100644 --- a/test/test.js +++ b/test/test.js @@ -183,6 +183,37 @@ describe('compress()', function(){ .end() }) + it('should not error when client aborts', function(done){ + var closed = false + var resp + var server = createServer({ threshold: 0 }, function (req, res) { + resp = res + req.on('close', function(){ closed = true }) + res.setHeader('Content-Type', 'text/plain') + res.setHeader('Content-Length', '2048') + res.write(new Buffer(1024)) + res.flush() + }) + + request(server) + .get('/') + .set('Accept-Encoding', 'gzip') + .request() + .on('response', function (res) { + var req = this + res.headers['content-encoding'].should.equal('gzip') + res.once('data', function(){ + req.abort() + setTimeout(function(){ + closed.should.be.true + resp.end(new Buffer(1024)) + done() + }, 10) + }) + }) + .end() + }) + describe('threshold', function(){ it('should not compress responses below the threshold size', function(done){ var server = createServer({ threshold: '1kb' }, function (req, res) {