Skip to content

Commit 993835a

Browse files
authored
Merge pull request #2608 from swimmio/fix-proxy-connect-missing-port
Fix missing port in proxy CONNECT when using the default HTTPS port
2 parents 51b0f66 + 0854192 commit 993835a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

packages/grpc-js/src/http_proxy.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
import { ChannelOptions } from './channel-options';
3131
import { GrpcUri, parseUri, splitHostPort, uriToString } from './uri-parser';
3232
import { URL } from 'url';
33+
import { DEFAULT_PORT } from './resolver-dns';
3334

3435
const TRACER_NAME = 'proxy';
3536

@@ -189,12 +190,19 @@ export function getProxiedConnection(
189190
if (parsedTarget === null) {
190191
return Promise.resolve<ProxyConnectionResult>({});
191192
}
193+
const splitHostPost = splitHostPort(parsedTarget.path);
194+
if (splitHostPost === null) {
195+
return Promise.resolve<ProxyConnectionResult>({});
196+
}
197+
const hostPort = `${splitHostPost.host}:${
198+
splitHostPost.port ?? DEFAULT_PORT
199+
}`;
192200
const options: http.RequestOptions = {
193201
method: 'CONNECT',
194-
path: parsedTarget.path,
202+
path: hostPort,
195203
};
196204
const headers: http.OutgoingHttpHeaders = {
197-
Host: parsedTarget.path,
205+
Host: hostPort,
198206
};
199207
// Connect to the subchannel address as a proxy
200208
if (isTcpSubchannelAddress(address)) {

packages/grpc-js/src/resolver-dns.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function trace(text: string): void {
4343
/**
4444
* The default TCP port to connect to if not explicitly specified in the target.
4545
*/
46-
const DEFAULT_PORT = 443;
46+
export const DEFAULT_PORT = 443;
4747

4848
const DEFAULT_MIN_TIME_BETWEEN_RESOLUTIONS_MS = 30_000;
4949

0 commit comments

Comments
 (0)