Skip to content

Commit a08e43d

Browse files
authored
Merge pull request #1902 from murgatroid99/grpc-js_http_proxy_fix_1.4
grpc-js: adds sometimes required Host header to proxy connection
2 parents 1b34e0f + 305623e commit a08e43d

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/grpc-js/src/http_proxy.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ export function getProxiedConnection(
190190
method: 'CONNECT',
191191
path: parsedTarget.path,
192192
};
193+
const headers: http.OutgoingHttpHeaders = {
194+
Host: parsedTarget.path,
195+
};
193196
// Connect to the subchannel address as a proxy
194197
if (isTcpSubchannelAddress(address)) {
195198
options.host = address.host;
@@ -198,14 +201,13 @@ export function getProxiedConnection(
198201
options.socketPath = address.path;
199202
}
200203
if ('grpc.http_connect_creds' in channelOptions) {
201-
options.headers = {
202-
'Proxy-Authorization':
203-
'Basic ' +
204-
Buffer.from(
205-
channelOptions['grpc.http_connect_creds'] as string
206-
).toString('base64'),
207-
};
204+
headers['Proxy-Authorization'] =
205+
'Basic ' +
206+
Buffer.from(
207+
channelOptions['grpc.http_connect_creds'] as string
208+
).toString('base64');
208209
}
210+
options.headers = headers
209211
const proxyAddressString = subchannelAddressToString(address);
210212
trace('Using proxy ' + proxyAddressString + ' to connect to ' + options.path);
211213
return new Promise<ProxyConnectionResult>((resolve, reject) => {

0 commit comments

Comments
 (0)