Skip to content

option "intercept" throw error when use a truncated gzip request. #177

@JanzenZhangChen

Description

@JanzenZhangChen

When using "intercept" option, the http request is using gzip,but the data is truncated.So the proxy will throw an error of
"Error: unexpected end of file
at Zlib._handle.onerror (zlib.js:370:17)
at Gunzip.Zlib._processChunk (zlib.js:538:30)
at zlibBufferSync (zlib.js:239:17)"
we can use a official method to solve this problem.
https://nodejs.org/api/zlib.html#zlib_compressing_http_requests_and_responses
(search truncated)

so I add some code in your lib.

function zipOrUnzip(method) {
return function(rspData, res) {
return (isResGzipped(res)) ? zlib[method](rspData, {
finishFlush: zlib.Z_SYNC_FLUSH //here
}) : rspData;
};
}

then the intercept option would be like:
intercept: function(rsp, data, req, res, callback) {
var resdata = data.toString(); //data would be Buffer
callback(null, resdata);
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions