decompress-response
Advanced tools
Comparing version 3.2.0 to 3.3.0
43
index.js
'use strict'; | ||
const PassThrough = require('stream').PassThrough; | ||
const zlib = require('zlib'); | ||
const mimicResponse = require('mimic-response'); | ||
// We define these manually to ensure they're always copied | ||
// even if they would move up the prototype chain | ||
// https://nodejs.org/api/http.html#http_class_http_incomingmessage | ||
const knownProps = [ | ||
'destroy', | ||
'setTimeout', | ||
'socket', | ||
'headers', | ||
'trailers', | ||
'rawHeaders', | ||
'statusCode', | ||
'httpVersion', | ||
'httpVersionMinor', | ||
'httpVersionMajor', | ||
'rawTrailers', | ||
'statusMessage' | ||
]; | ||
const copyProps = (fromStream, toStream) => { | ||
const toProps = Object.keys(toStream); | ||
const fromProps = new Set(Object.keys(fromStream).concat(knownProps)); | ||
for (const prop of fromProps) { | ||
// Don't overwrite existing properties | ||
if (toProps.indexOf(prop) !== -1) { | ||
continue; | ||
} | ||
toStream[prop] = typeof prop === 'function' ? fromStream[prop].bind(fromStream) : fromStream[prop]; | ||
} | ||
}; | ||
module.exports = res => { | ||
module.exports = response => { | ||
// TODO: Use Array#includes when targeting Node.js 6 | ||
if (['gzip', 'deflate'].indexOf(res.headers['content-encoding']) === -1) { | ||
return res; | ||
if (['gzip', 'deflate'].indexOf(response.headers['content-encoding']) === -1) { | ||
return response; | ||
} | ||
@@ -46,3 +15,3 @@ | ||
copyProps(res, stream); | ||
mimicResponse(response, stream); | ||
@@ -58,5 +27,5 @@ unzip.on('error', err => { | ||
res.pipe(unzip).pipe(stream); | ||
response.pipe(unzip).pipe(stream); | ||
return stream; | ||
}; |
{ | ||
"name": "decompress-response", | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"description": "Decompress a HTTP response if needed", | ||
@@ -44,9 +44,11 @@ "license": "MIT", | ||
], | ||
"dependencies": { | ||
"mimic-response": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"get-stream": "^3.0.0", | ||
"pify": "^2.3.0", | ||
"rfpify": "^1.0.0", | ||
"pify": "^3.0.0", | ||
"xo": "*" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4
3540
1
22
+ Addedmimic-response@^1.0.0
+ Addedmimic-response@1.0.1(transitive)