From 5640798fe4c189fa6aa7ba0d44ef77d2b1ef47a5 Mon Sep 17 00:00:00 2001 From: nsankbeil Date: Mon, 3 Jul 2023 11:49:16 -0400 Subject: [PATCH] fix: handle missing EOF when decompressing response Closes: #1609 --- src/utils/proxy/http.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/utils/proxy/http.js b/src/utils/proxy/http.js index 72f65be3b..61f415855 100644 --- a/src/utils/proxy/http.js +++ b/src/utils/proxy/http.js @@ -1,6 +1,6 @@ /* eslint-disable prefer-promise-reject-errors */ /* eslint-disable no-param-reassign */ -import { createUnzip } from "node:zlib"; +import { createUnzip, constants as zlibConstants } from "node:zlib"; import { http, https } from "follow-redirects"; @@ -34,7 +34,11 @@ function handleRequest(requestor, url, params) { let responseContent = response; if (contentEncoding === 'gzip' || contentEncoding === 'deflate') { - responseContent = createUnzip(); + responseContent = createUnzip({ + flush: zlibConstants.Z_SYNC_FLUSH, + finishFlush: zlibConstants.Z_SYNC_FLUSH + }); + // zlib errors responseContent.on("error", (e) => { logger.error(e); @@ -103,6 +107,6 @@ export async function httpProxy(url, params = {}) { constructedUrl.pathname ); logger.error(err); - return [500, "application/json", { error: {message: err?.message ?? "Unknown error", url, rawError: err} }, null]; + return [500, "application/json", { error: { message: err?.message ?? "Unknown error", url, rawError: err } }, null]; } }