From 305623e2eba833af1432685872f03cad8041cb97 Mon Sep 17 00:00:00 2001 From: bbesset Date: Wed, 15 Sep 2021 09:03:49 +0200 Subject: [PATCH] adds sometimes required Host header to proxy connection --- packages/grpc-js/src/http_proxy.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/grpc-js/src/http_proxy.ts b/packages/grpc-js/src/http_proxy.ts index 14e88f06..248949a8 100644 --- a/packages/grpc-js/src/http_proxy.ts +++ b/packages/grpc-js/src/http_proxy.ts @@ -190,6 +190,9 @@ export function getProxiedConnection( method: 'CONNECT', path: parsedTarget.path, }; + const headers: http.OutgoingHttpHeaders = { + Host: parsedTarget.path, + }; // Connect to the subchannel address as a proxy if (isTcpSubchannelAddress(address)) { options.host = address.host; @@ -198,14 +201,13 @@ export function getProxiedConnection( options.socketPath = address.path; } if ('grpc.http_connect_creds' in channelOptions) { - options.headers = { - 'Proxy-Authorization': - 'Basic ' + - Buffer.from( - channelOptions['grpc.http_connect_creds'] as string - ).toString('base64'), - }; + headers['Proxy-Authorization'] = + 'Basic ' + + Buffer.from( + channelOptions['grpc.http_connect_creds'] as string + ).toString('base64'); } + options.headers = headers const proxyAddressString = subchannelAddressToString(address); trace('Using proxy ' + proxyAddressString + ' to connect to ' + options.path); return new Promise((resolve, reject) => {