Browse Source

Use unzip-response to unzip stream

http2
Vsevolod Strukchinsky 10 years ago
parent
commit
b38a7975cc
  1. 16
      index.js
  2. 3
      package.json

16
index.js

@ -4,7 +4,6 @@ var http = require('http');
var https = require('https'); var https = require('https');
var urlLib = require('url'); var urlLib = require('url');
var util = require('util'); var util = require('util');
var zlib = require('zlib');
var querystring = require('querystring'); var querystring = require('querystring');
var objectAssign = require('object-assign'); var objectAssign = require('object-assign');
var duplexify = require('duplexify'); var duplexify = require('duplexify');
@ -16,6 +15,7 @@ var lowercaseKeys = require('lowercase-keys');
var isRedirect = require('is-redirect'); var isRedirect = require('is-redirect');
var NestedErrorStacks = require('nested-error-stacks'); var NestedErrorStacks = require('nested-error-stacks');
var pinkiePromise = require('pinkie-promise'); var pinkiePromise = require('pinkie-promise');
var unzipResponse = require('unzip-response');
function GotError(message, nested) { function GotError(message, nested) {
NestedErrorStacks.call(this, message, nested); NestedErrorStacks.call(this, message, nested);
@ -54,19 +54,7 @@ function requestAsEventEmitter(opts) {
return; return;
} }
if (['gzip', 'deflate'].indexOf(res.headers['content-encoding']) !== -1) { res = unzipResponse(res);
var unzip = zlib.createUnzip();
unzip.httpVersion = res.httpVersion;
unzip.headers = res.headers;
unzip.rawHeaders = res.rawHeaders;
unzip.trailers = res.trailers;
unzip.rawTrailers = res.rawTrailers;
unzip.setTimeout = res.setTimeout.bind(res);
unzip.statusCode = res.statusCode;
unzip.statusMessage = res.statusMessage;
unzip.socket = res.socket;
res = res.pipe(unzip);
}
ee.emit('response', res); ee.emit('response', res);
}).once('error', function (err) { }).once('error', function (err) {

3
package.json

@ -50,7 +50,8 @@
"pinkie-promise": "^1.0.0", "pinkie-promise": "^1.0.0",
"prepend-http": "^1.0.0", "prepend-http": "^1.0.0",
"read-all-stream": "^3.0.0", "read-all-stream": "^3.0.0",
"timed-out": "^2.0.0" "timed-out": "^2.0.0",
"unzip-response": "^1.0.0"
}, },
"devDependencies": { "devDependencies": {
"from2-array": "0.0.3", "from2-array": "0.0.3",

Loading…
Cancel
Save