From b38a7975cc3a2aaa66856a783b71e5671fdcb83f Mon Sep 17 00:00:00 2001 From: Vsevolod Strukchinsky Date: Sat, 18 Jul 2015 21:34:05 +0500 Subject: [PATCH] Use unzip-response to unzip stream --- index.js | 16 ++-------------- package.json | 3 ++- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 44f453a..150cd90 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,6 @@ var http = require('http'); var https = require('https'); var urlLib = require('url'); var util = require('util'); -var zlib = require('zlib'); var querystring = require('querystring'); var objectAssign = require('object-assign'); var duplexify = require('duplexify'); @@ -16,6 +15,7 @@ var lowercaseKeys = require('lowercase-keys'); var isRedirect = require('is-redirect'); var NestedErrorStacks = require('nested-error-stacks'); var pinkiePromise = require('pinkie-promise'); +var unzipResponse = require('unzip-response'); function GotError(message, nested) { NestedErrorStacks.call(this, message, nested); @@ -54,19 +54,7 @@ function requestAsEventEmitter(opts) { return; } - if (['gzip', 'deflate'].indexOf(res.headers['content-encoding']) !== -1) { - 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); - } + res = unzipResponse(res); ee.emit('response', res); }).once('error', function (err) { diff --git a/package.json b/package.json index 7570a97..78fbcef 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,8 @@ "pinkie-promise": "^1.0.0", "prepend-http": "^1.0.0", "read-all-stream": "^3.0.0", - "timed-out": "^2.0.0" + "timed-out": "^2.0.0", + "unzip-response": "^1.0.0" }, "devDependencies": { "from2-array": "0.0.3",