Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Response write/end to noop() when request aborted #724

Merged
merged 1 commit into from

3 participants

@ZJONSSON

Had problems with compress module when the request are aborted by the client:


Error: Cannot write after end
at Gzip.write (zlib.js:307:31)
at ServerResponse.module.exports.res.write (c:\program files\nodejs\node_mo
ules\connect\lib\middleware\compress.js:81:18)

I'm not sure if this is the most efficient fix, but pointing res.write and res.end to noop() eliminates the error.

@skaapgif

Just faced the same problem.

@ZJONSSON

@skaapgif did you try my fix posted above. You can simply add it manually to your request object:

 // Remove response write/end if request aborted
req.on("close",function() {
  res.write = res.end = function() {}
});
@tj tj merged commit 2b9c4e7 into senchalabs:master

1 check failed

Details default The Travis build failed
@tj
Owner
tj commented

probably would be best if we did some .finished bool check or something in there but this should work for now

@ZJONSSON

Thanks, yes exactly!

@ZJONSSON ZJONSSON deleted the ZJONSSON:compress_aborted branch
@Fishrock123 Fishrock123 referenced this pull request in expressjs/compression
Closed

Response write/end to noop() when request aborted #8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 11, 2013
  1. @ZJONSSON
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 0 deletions.
  1. +5 −0 lib/middleware/compress.js
View
5 lib/middleware/compress.js
@@ -73,6 +73,11 @@ module.exports = function compress(options) {
// vary
res.setHeader('Vary', 'Accept-Encoding');
+ // Remove response write/end if request aborted
+ req.on("close",function() {
+ res.write = res.end = function() {}
+ });
+
// proxy
res.write = function(chunk, encoding){
Something went wrong with that request. Please try again.