do not unzip the response body when it's empty, such as 304

also remove the delete operatoin for 'accept-encoding' in the test utils, since AnyProxy will not remove the header now
This commit is contained in:
砚然
2017-12-14 23:58:52 +08:00
parent 87c4eeec94
commit b6c7088965
5 changed files with 37 additions and 13 deletions

View File

@@ -93,11 +93,12 @@ function fetchRemoteResponse(protocol, options, reqData, config) {
fulfill(resDataStream);
} else {
const serverResData = Buffer.concat(resDataChunks);
const originContentLen = util.getByteSize(serverResData);
// set origin content length into header
resHeader['x-anyproxy-origin-content-length'] = originContentLen;
// put origin content length into header
resHeader['x-anyproxy-origin-content-length'] = util.getByteSize(serverResData);
if (ifServerGzipped) {
// only do unzip when there is res data
if (ifServerGzipped && originContentLen) {
zlib.gunzip(serverResData, (err, buff) => { // TODO test case to cover
if (err) {
rejectParsing(err);
@@ -105,7 +106,7 @@ function fetchRemoteResponse(protocol, options, reqData, config) {
fulfill(buff);
}
});
} else if (isServerDeflated) {
} else if (isServerDeflated && originContentLen) {
zlib.inflateRaw(serverResData, (err, buff) => { // TODO test case to cover
if (err) {
rejectParsing(err);