Merge pull request #1478 from murgatroid99/grpc-js_authority_port

grpc-js: Add port to :authority, leave it out of service_url
This commit is contained in:
Michael Lumish 2020-06-17 09:15:38 -07:00 committed by GitHub
commit a0fb455514
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 ?? 'localhost';
/* 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;
}
}