diff options
author | isaacs <i@izs.me> | 2014-03-19 09:25:40 -0700 |
---|---|---|
committer | isaacs <i@izs.me> | 2014-03-19 09:26:05 -0700 |
commit | a65c1aaf3afe21a34cae7b4ad266a6f2723704d1 (patch) | |
tree | 61e4c2a3b069f78d8ef5ae635a887cda13ec1c15 /deps/npm/node_modules/npm-registry-client/lib/request.js | |
parent | 43a29f53ca11ab48e1d1ef6b2a0e673ae43a42a0 (diff) | |
download | node-npm-1.4.6.tar.gz |
npm: upgrade to 1.4.6npm-1.4.6
Diffstat (limited to 'deps/npm/node_modules/npm-registry-client/lib/request.js')
-rw-r--r-- | deps/npm/node_modules/npm-registry-client/lib/request.js | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/deps/npm/node_modules/npm-registry-client/lib/request.js b/deps/npm/node_modules/npm-registry-client/lib/request.js index b2cff11a7..c11dc9ca3 100644 --- a/deps/npm/node_modules/npm-registry-client/lib/request.js +++ b/deps/npm/node_modules/npm-registry-client/lib/request.js @@ -1,6 +1,7 @@ module.exports = regRequest var url = require("url") + , zlib = require("zlib") , fs = require("graceful-fs") , rm = require("rimraf") , asyncMap = require("slide").asyncMap @@ -128,6 +129,7 @@ function makeRequest (method, remote, where, what, etag, nofollow, cb_) { if (strict === undefined) strict = true var opts = { url: remote , method: method + , encoding: null // tell request let body be Buffer instance , ca: this.conf.get('ca') , localAddress: this.conf.get('local-address') , cert: this.conf.get('cert') @@ -140,6 +142,7 @@ function makeRequest (method, remote, where, what, etag, nofollow, cb_) { } headers.accept = "application/json" + headers['accept-encoding'] = 'gzip' headers["user-agent"] = this.conf.get('user-agent') || 'node/' + process.version @@ -170,7 +173,7 @@ function makeRequest (method, remote, where, what, etag, nofollow, cb_) { this.log.http(method, remote.href || "/") var done = requestDone.call(this, method, where, cb) - var req = request(opts, done) + var req = request(opts, decodeResponseBody(done)) req.on("error", cb) req.on("socket", function (s) { @@ -182,6 +185,20 @@ function makeRequest (method, remote, where, what, etag, nofollow, cb_) { } } +function decodeResponseBody(cb) { + return function (er, response, data) { + if (er) return cb(er, response, data) + + if (response.headers['content-encoding'] !== 'gzip') return cb(er, response, data) + + zlib.gunzip(data, function (er, buf) { + if (er) return cb(er, response, data) + + cb(null, response, buf) + }) + } +} + // cb(er, parsed, raw, response) function requestDone (method, where, cb) { return function (er, response, data) { |