Skip to content

Commit 0f617c7

Browse files
committed
Checking OutgoingMessage.prototype.
1 parent 79c6b75 commit 0f617c7

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ var debug = require('debug')('compression')
2121
var onHeaders = require('on-headers')
2222
var vary = require('vary')
2323
var zlib = require('zlib')
24+
var OutgoingMessage = require('http').OutgoingMessage
25+
var hasCallback = (OutgoingMessage.prototype.write.length === 3)
2426

2527
/**
2628
* Module exports.
@@ -80,7 +82,7 @@ function compression (options) {
8082
return false
8183
}
8284

83-
cb = (res._write.length === 3) ? cb : null
85+
cb = hasCallback ? cb : null
8486

8587
if (!this._header) {
8688
this._implicitHeader()
@@ -96,7 +98,7 @@ function compression (options) {
9698
return false
9799
}
98100

99-
cb = (res._end.length === 3) ? cb : null
101+
cb = hasCallback ? cb : null
100102

101103
if (!this._header) {
102104
// estimate the length

test/compression.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ var bytes = require('bytes')
33
var crypto = require('crypto')
44
var http = require('http')
55
var request = require('supertest')
6+
var OutgoingMessage = http.OutgoingMessage
7+
var hasCallbacks = (OutgoingMessage.prototype.write.length === 3)
68

79
var compression = require('..')
810

@@ -679,10 +681,8 @@ describe('compression()', function () {
679681

680682
describe('when callbacks are used', function () {
681683
it('should call the passed callbacks in the order passed when compressing', function (done) {
682-
var hasCallbacks = false
683684
var callbackOutput = []
684685
var server = createServer(null, function (req, res) {
685-
hasCallbacks = (res._write.length === 3 && res._end.length === 3)
686686
res.setHeader('Content-Type', 'text/plain')
687687
res.write('Hello', null, function () {
688688
callbackOutput.push(0)
@@ -712,10 +712,8 @@ describe('compression()', function () {
712712
})
713713

714714
it('should call the passed callbacks in the order passed when not compressing', function (done) {
715-
var hasCallbacks = false
716715
var callbackOutput = []
717716
var server = createServer(null, function (req, res) {
718-
hasCallbacks = (res._write.length === 3 && res._end.length === 3)
719717
res.setHeader('Cache-Control', 'no-transform')
720718
res.setHeader('Content-Type', 'text/plain')
721719
res.write('hello,', null, function () {

0 commit comments

Comments
 (0)