Do not try to pipe Gzip responses with no body#2176
Conversation
request.js
Outdated
|
|
||
| var responseContent | ||
| if (self.gzip) { | ||
| if (self.gzip && self.method !== 'HEAD') { |
There was a problem hiding this comment.
This will fix the particular issue with HEAD requests, but will still cause issues if the response is empty for say a GET. A better way of handling would be to catch the Error from zlib.
There was a problem hiding this comment.
Figuring out if the response is empty beforehand would be great, will think about it. I would rather not use try/catch if there is some other way to detect the condition.
There was a problem hiding this comment.
Unfortunately there is no reliable way to determine upfront if the response body is empty. And in fact the error is thrown because the gzip content is invalid which may happen even if you have a body.
So the least we can do is forward the error events so that the user can handle them accordingly. Which means that you will receive an error when the request method is GET, the gzip option is set to true, and there is no response body.
There was a problem hiding this comment.
Anyway still this PR fixes the mentioned issue in the description which is the most common use case.
@czardoz you can open up another issue and point to this one, so we can have a discussion there.
|
Thanks, @simov! |
|
LGTM! 🍰 |
|
Version 2.72 is out! ✨ |
Do not try to pipe Gzip responses with no body
Fixes #2045
Fixes #2177