Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JanzenZhangChen opened this issue Mar 25, 2017 · 7 comments
Open
Labels

Comments

@JanzenZhangChen
Copy link

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);
},

@monkpow monkpow added the bug label Mar 29, 2017
@monkpow
Copy link
Collaborator

monkpow commented Mar 29, 2017

@JanzenZhangChen Thank you for this report and suggestion. Do you have a test case that's failing that I can use to verify your fix? Thanks!

@JanzenZhangChen
Copy link
Author

JanzenZhangChen commented Mar 31, 2017

sorry, i cant provide our cgi to you,but I found one in cn.bing.com(china)

http://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&nc=1490973090201&pid=hp&video=1

if you use fiddler to catch this request, in Raw section of response body, it said:
*** FIDDLER: RawDisplay truncated at 128 characters. Right-click to disable truncation. ***

@phenomnomnominal
Copy link

The fix suggested by @JanzenZhangChen fixed some issues I was getting too. Do you need a PR?

@monkpow
Copy link
Collaborator

monkpow commented Apr 29, 2017

I found an separate bug in the parser for zip that I think may have been causing this. The patch is in the 1.0.* line.

If you're still experiencing the issue, I'd be very happy to get a PR if you would like to accelerate resolution.

@JanzenZhangChen
Copy link
Author

JanzenZhangChen commented May 5, 2017

I created a PR to the project. I couldnt pass the "on the nose" mocha test. And I have no idea how to fix this problem.

@jpetitcolas
Copy link

jpetitcolas commented May 16, 2017

Note we have the issue when receiving a 204 (No-content) response on a DELETE request. We circumvent the issue using a code like:

if (srcReq.method === 'DELETE') {
    delete proxyReq.headers['accept-encoding'];
}

@scr4bble
Copy link

Hi guys, any update on this ? I am experiencing the same issue.

zlib.js:421
      throw error;
      ^
Error: unexpected end of file
    at Gunzip.zlibOnError (zlib.js:153:15)
    at Gunzip._processChunk (zlib.js:411:30)
    at zlibBufferSync (zlib.js:144:38)
    at Object.gunzipSync (zlib.js:590:14)
    at /usr/src/app/node_modules/express-http-proxy/index.js:323:46
    at IncomingMessage.<anonymous> (/usr/src/app/node_modules/express-http-proxy/index.js:100:23)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants