Files
vercel/packages/node/test/dev-fixtures/serverless-fetch.js
Kiko Beats 5e5332fbc9 [node] fix decompress mismatching (#10184)
This PR disabled `node-fetch` default compression handling when the
response is not streamed.

The default behavior in node-fetch is to handle the compression. That's
great if you interact with node-fetch as user, but bad if you use it as
intermediate proxy server, since it's creating a mismatching related
with the body format and length expectations.

Instead, we disable compression, get the buffered response and compress
it again if needed.

---------

Co-authored-by: Sean Massa <EndangeredMassa@gmail.com>
2023-07-07 12:33:05 -06:00

11 lines
378 B
JavaScript

const baseUrl = ({ headers }) =>
`${headers.get('x-forwarded-proto')}://${headers.get('x-forwarded-host')}`;
export function GET(request) {
const { searchParams } = new URL(request.url, baseUrl(request));
const url = searchParams.get('url');
const encoding = searchParams.get('encoding');
const serverUrl = `${url}?encoding=${encoding}`;
return fetch(serverUrl);
}