koa-better-http-proxy icon indicating copy to clipboard operation
koa-better-http-proxy copied to clipboard

fix: Handle empty gzipped response body from proxy

Open jeremy-daley-kr opened this issue 2 years ago • 1 comments

A HEAD method does not have a body. If the content-encoding is gzip, KBHP should NOT try to unzip the response if Buffer.byteLength is zero, or else we see this:

 Error: unexpected end of file
      at Zlib.zlibOnError [as onerror] (node:zlib:190:17)
      at Zlib.callbackTrampoline (node:internal/async_hooks:130:17)
      at processChunkSync (node:zlib:456:12)
      at zlibBufferSync (node:zlib:178:12)
      at Object.syncBufferWrapper [as gunzipSync] (node:zlib:791:14)
      at /Users/redacted/Code/contrib/koa-better-http-proxy/app/steps/decorateUserRes.js:13:46
      at decorateProxyResBody (/Users/redacted/Code/contrib/koa-better-http-proxy/app/steps/decorateUserRes.js:45:22)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)

jeremy-daley-kr avatar Feb 24 '23 16:02 jeremy-daley-kr

@nsimmons Can you please consider merging this PR? Thanks!

jeremy-daley-kr avatar Oct 10 '23 19:10 jeremy-daley-kr