Merge pull request #1902 from murgatroid99/grpc-js_http_proxy_fix_1.4

grpc-js: adds sometimes required Host header to proxy connection
This commit is contained in:
Michael Lumish 2021-09-15 11:15:50 -07:00 committed by GitHub
commit a08e43d468
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 7 deletions

View File

@ -190,6 +190,9 @@ export function getProxiedConnection(
method: 'CONNECT', method: 'CONNECT',
path: parsedTarget.path, path: parsedTarget.path,
}; };
const headers: http.OutgoingHttpHeaders = {
Host: parsedTarget.path,
};
// Connect to the subchannel address as a proxy // Connect to the subchannel address as a proxy
if (isTcpSubchannelAddress(address)) { if (isTcpSubchannelAddress(address)) {
options.host = address.host; options.host = address.host;
@ -198,14 +201,13 @@ export function getProxiedConnection(
options.socketPath = address.path; options.socketPath = address.path;
} }
if ('grpc.http_connect_creds' in channelOptions) { if ('grpc.http_connect_creds' in channelOptions) {
options.headers = { headers['Proxy-Authorization'] =
'Proxy-Authorization': 'Basic ' +
'Basic ' + Buffer.from(
Buffer.from( channelOptions['grpc.http_connect_creds'] as string
channelOptions['grpc.http_connect_creds'] as string ).toString('base64');
).toString('base64'),
};
} }
options.headers = headers
const proxyAddressString = subchannelAddressToString(address); const proxyAddressString = subchannelAddressToString(address);
trace('Using proxy ' + proxyAddressString + ' to connect to ' + options.path); trace('Using proxy ' + proxyAddressString + ' to connect to ' + options.path);
return new Promise<ProxyConnectionResult>((resolve, reject) => { return new Promise<ProxyConnectionResult>((resolve, reject) => {