Skip to content

Commit 5d5e662

Browse files
committed
[WIP]: use original functions (write, end)
Signed-off-by: Sebastian Beltran <[email protected]>
1 parent 43569e2 commit 5d5e662

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ function compression (options) {
8989
// proxy
9090

9191
res.write = function write (chunk, encoding, callback) {
92+
if (isFinished(res) || ended) {
93+
return _write.apply(this, arguments)
94+
}
95+
9296
if (!res.headersSent) {
9397
this.writeHead(this.statusCode)
9498
}
@@ -103,6 +107,10 @@ function compression (options) {
103107
}
104108

105109
res.end = function end (chunk, encoding, callback) {
110+
if (isFinished(res) || ended) {
111+
return _end.apply(this, arguments)
112+
}
113+
106114
if (!callback) {
107115
if (typeof chunk === 'function') {
108116
callback = chunk
@@ -226,11 +234,6 @@ function compression (options) {
226234
res.setHeader('Content-Encoding', method)
227235
res.removeHeader('Content-Length')
228236

229-
// emit error on response
230-
stream.on('error', function (err) {
231-
res.emit('error', err)
232-
})
233-
234237
// compression
235238
stream.on('data', function onStreamData (chunk) {
236239
if (isFinished(res)) {

0 commit comments

Comments
 (0)