-
-
Notifications
You must be signed in to change notification settings - Fork 242
Callback implementation and tests for write and end #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v2
Are you sure you want to change the base?
Changes from 3 commits
a68265e
a7c7615
ce0f02f
9d55cfd
4a8e87f
2fdf90f
388bcc1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
unreleased | ||
========== | ||
|
||
1.7.0 / 2017-01-04 | ||
================== | ||
* Callbacks available in `write` and `end` when supported in nodejs (requires nodejs >= 0.12.x) | ||
bjohansebas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
* deps: [email protected] | ||
* deps: compressible@~2.0.9 | ||
- Fix regex fallback to not override `compressible: false` in db | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ var debug = require('debug')('compression') | |
var onHeaders = require('on-headers') | ||
var vary = require('vary') | ||
var zlib = require('zlib') | ||
var http = require('http') | ||
|
||
/** | ||
* Module exports. | ||
|
@@ -35,6 +36,7 @@ module.exports.filter = shouldCompress | |
*/ | ||
|
||
var cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/ | ||
var nodeHasCallbacks = (http.OutgoingMessage.prototype.write.length === 3 && http.OutgoingMessage.prototype.end.length === 3) | ||
|
||
|
||
/** | ||
* Compress response data with gzip / deflate. | ||
|
@@ -74,7 +76,7 @@ function compression (options) { | |
|
||
// proxy | ||
|
||
res.write = function write (chunk, encoding) { | ||
res.write = function write (chunk, encoding, cb) { | ||
if (ended) { | ||
return false | ||
} | ||
|
@@ -84,11 +86,11 @@ function compression (options) { | |
} | ||
|
||
return stream | ||
? stream.write(new Buffer(chunk, encoding)) | ||
: _write.call(this, chunk, encoding) | ||
? stream.write(new Buffer(chunk, encoding), nodeHasCallbacks ? cb : undefined) | ||
: _write.call(this, chunk, encoding, nodeHasCallbacks ? cb : undefined) | ||
} | ||
|
||
res.end = function end (chunk, encoding) { | ||
res.end = function end (chunk, encoding, cb) { | ||
if (ended) { | ||
return false | ||
} | ||
|
@@ -103,16 +105,16 @@ function compression (options) { | |
} | ||
|
||
if (!stream) { | ||
return _end.call(this, chunk, encoding) | ||
return _end.call(this, chunk, encoding, nodeHasCallbacks ? cb : undefined) | ||
} | ||
|
||
// mark ended | ||
ended = true | ||
|
||
// write Buffer for Node.js 0.8 | ||
return chunk | ||
? stream.end(new Buffer(chunk, encoding)) | ||
: stream.end() | ||
? stream.end(new Buffer(chunk, encoding), nodeHasCallbacks ? cb : undefined) | ||
: stream.end(null, null, nodeHasCallbacks ? cb : undefined) | ||
} | ||
|
||
res.on = function on (type, listener) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "compression", | ||
"description": "Node.js compression middleware", | ||
"version": "1.6.2", | ||
"version": "1.7.0", | ||
bjohansebas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
"contributors": [ | ||
"Douglas Christopher Wilson <[email protected]>", | ||
"Jonathan Ong <[email protected]> (http://jongleberry.com)" | ||
|
Uh oh!
There was an error while loading. Please reload this page.