From 01dbc34eb1ed96438c6d30236c6341aae1d0e708 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Tue, 16 Jun 2020 11:30:51 -0700 Subject: [PATCH] grpc-js: Add port to :authority, leave it out of service_url --- packages/grpc-js/src/call-credentials-filter.ts | 4 +++- packages/grpc-js/src/resolver-dns.ts | 7 +------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/grpc-js/src/call-credentials-filter.ts b/packages/grpc-js/src/call-credentials-filter.ts index d39af832..a5459b53 100644 --- a/packages/grpc-js/src/call-credentials-filter.ts +++ b/packages/grpc-js/src/call-credentials-filter.ts @@ -20,6 +20,7 @@ import { Channel } from './channel'; import { BaseFilter, Filter, FilterFactory } from './filter'; import { Metadata } from './metadata'; import { Status } from './constants'; +import { splitHostPort } from './uri-parser'; export class CallCredentialsFilter extends BaseFilter implements Filter { private serviceUrl: string; @@ -38,9 +39,10 @@ export class CallCredentialsFilter extends BaseFilter implements Filter { if (splitPath.length >= 2) { serviceName = splitPath[1]; } + const hostname = splitHostPort(stream.getHost()).host; /* Currently, call credentials are only allowed on HTTPS connections, so we * can assume that the scheme is "https" */ - this.serviceUrl = `https://${stream.getHost()}/${serviceName}`; + this.serviceUrl = `https://${hostname}/${serviceName}`; } async sendMetadata(metadata: Promise): Promise { diff --git a/packages/grpc-js/src/resolver-dns.ts b/packages/grpc-js/src/resolver-dns.ts index 016f3bd1..8a7f4f22 100644 --- a/packages/grpc-js/src/resolver-dns.ts +++ b/packages/grpc-js/src/resolver-dns.ts @@ -269,12 +269,7 @@ class DnsResolver implements Resolver { * @param target */ static getDefaultAuthority(target: GrpcUri): string { - const hostPort = splitHostPort(target.path); - if (hostPort !== null) { - return hostPort.host; - } else { - throw new Error(`Failed to parse target ${uriToString(target)}`); - } + return target.path; } }