grpc-js: Add port to :authority, leave it out of service_url

This commit is contained in:
Michael Lumish 2020-06-16 11:30:51 -07:00
parent 1d14203c38
commit 01dbc34eb1
2 changed files with 4 additions and 7 deletions

View File

@ -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<Metadata>): Promise<Metadata> {

View File

@ -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;
}
}