From 316b7bff6197260002b0e7c5c461d1df354c85b8 Mon Sep 17 00:00:00 2001 From: bobalong79 Date: Mon, 1 Mar 2021 18:01:44 +0000 Subject: [PATCH] Add rationale explaining why we do the header modifications in the filter --- plugins/proxy-backend/src/service/router.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/proxy-backend/src/service/router.ts b/plugins/proxy-backend/src/service/router.ts index 1798c56cc6..c4da4151bb 100644 --- a/plugins/proxy-backend/src/service/router.ts +++ b/plugins/proxy-backend/src/service/router.ts @@ -102,6 +102,11 @@ export function buildMiddleware( // Use the custom middleware filter to do two things: // 1. Remove any headers not in the allow list to stop them being forwarded // 2. Only permit the allowed HTTP methods if configured + // + // We are filtering the proxy request headers here rather than in + // `onProxyReq` becuase when global-agent is enabled then `onProxyReq` + // fires _after_ the agent has already sent the headers to the proxy + // target, causing a ERR_HTTP_HEADERS_SENT crash const filter = (_pathname: string, req: http.IncomingMessage): boolean => { const headerNames = Object.keys(req.headers); headerNames.forEach(h => {