Skip to content

Commit

Permalink
Always attempt to decompress data - even if an error has occurred
Browse files Browse the repository at this point in the history
This also fixes a bug with decompressing 404 errors - as you may want to
save or see the (decompressed) error page.
  • Loading branch information
danielbankhead committed Feb 18, 2017
1 parent f684dde commit d254f2c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 0 additions & 2 deletions docs/request.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,6 @@
- `using` STRING
- The tool used to decompress the data

- _NOTE_: If `null` check `responseHeaders['content-encoding']` as it is possible the decompression was not available for this request

- `error` OBJECT
- The error data, if any
- If `null`, _great_
Expand Down
14 changes: 12 additions & 2 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ function decompressData (results, callback) {
case 'gzip':
zlib.gunzip(results.data, (error, result) => {
if (error !== null) {
results.error = {type: 'http-gunzip-failed', details: error}
if (results.error === null) {
results.error = {type: 'http-gunzip-failed', details: error}
}
} else {
results.data = result
results.decompressed = {
Expand All @@ -55,7 +57,9 @@ function decompressData (results, callback) {
case 'deflate':
zlib.inflate(results.data, (error, result) => {
if (error !== null) {
results.error = {type: 'http-inflate-failed', details: error}
if (results.error === null) {
results.error = {type: 'http-inflate-failed', details: error}
}
} else {
results.data = result
results.decompressed = {
Expand All @@ -67,6 +71,12 @@ function decompressData (results, callback) {
processCallback(results, callback)
})
break

case undefined:
case null:
case '':
processCallback(results, callback)
break
default:
results.error = {type: 'http-unknown-content-encoding'}
processCallback(results, callback)
Expand Down

0 comments on commit d254f2c

Please sign in to comment.