Comparing version 0.0.38 to 0.0.39
@@ -15,2 +15,3 @@ /** | ||
var urlencode = require('urlencode'); | ||
var zlib = require('zlib'); | ||
@@ -29,2 +30,5 @@ function HttpProtocol() { | ||
config = Protocol.normalizeConfig(config); | ||
if (config.disableGzip === undefined) { | ||
config.disableGzip = true; | ||
} | ||
if (typeof config.query !== 'object') { | ||
@@ -54,2 +58,9 @@ config.query = urlencode.parse(config.query, { | ||
} | ||
if (config.disableGzip) { | ||
if (config.headers && config.headers['accept-encoding']) { | ||
config.headers['accept-encoding'] = ''; | ||
} | ||
} | ||
var opt = { | ||
@@ -64,3 +75,2 @@ host: config.server.host, | ||
}; | ||
var request; | ||
@@ -83,5 +93,18 @@ | ||
} | ||
res.pipe(response); | ||
// 添加 gzip与deflate 处理 | ||
switch (config.headers ? res.headers['content-encoding'] : '') { | ||
// or, just use zlib.createUnzip() to handle both cases | ||
case 'gzip': | ||
res.pipe(zlib.createGunzip()).pipe(response); | ||
break; | ||
case 'deflate': | ||
res.pipe(zlib.createInflate()).pipe(response); | ||
break; | ||
default: | ||
res.pipe(response); | ||
break; | ||
} | ||
callback && callback(response); | ||
}); | ||
if (config.payload) { | ||
@@ -88,0 +111,0 @@ req.write(config.payload); |
{ | ||
"name": "node-ral", | ||
"version": "0.0.38", | ||
"version": "0.0.39", | ||
"description": "a rpc client for node", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
282826
7951