Merge pull request #2608 from swimmio/fix-proxy-connect-missing-port

Fix missing port in proxy CONNECT when using the default HTTPS port
This commit is contained in:
Michael Lumish 2023-10-30 16:46:06 -07:00 committed by GitHub
commit 993835a0ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -30,6 +30,7 @@ import {
import { ChannelOptions } from './channel-options';
import { GrpcUri, parseUri, splitHostPort, uriToString } from './uri-parser';
import { URL } from 'url';
import { DEFAULT_PORT } from './resolver-dns';
const TRACER_NAME = 'proxy';
@ -189,12 +190,19 @@ export function getProxiedConnection(
if (parsedTarget === null) {
return Promise.resolve<ProxyConnectionResult>({});
}
const splitHostPost = splitHostPort(parsedTarget.path);
if (splitHostPost === null) {
return Promise.resolve<ProxyConnectionResult>({});
}
const hostPort = `${splitHostPost.host}:${
splitHostPost.port ?? DEFAULT_PORT
}`;
const options: http.RequestOptions = {
method: 'CONNECT',
path: parsedTarget.path,
path: hostPort,
};
const headers: http.OutgoingHttpHeaders = {
Host: parsedTarget.path,
Host: hostPort,
};
// Connect to the subchannel address as a proxy
if (isTcpSubchannelAddress(address)) {

View File

@ -43,7 +43,7 @@ function trace(text: string): void {
/**
* The default TCP port to connect to if not explicitly specified in the target.
*/
const DEFAULT_PORT = 443;
export const DEFAULT_PORT = 443;
const DEFAULT_MIN_TIME_BETWEEN_RESOLUTIONS_MS = 30_000;