Merge pull request #500 from murgatroid99/pure_js_channel_args_warning

Pure JS: add warnings for unhandled channel options
This commit is contained in:
Michael Lumish 2018-08-20 13:48:14 -07:00 committed by GitHub
commit 0ec9fed4bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 16 deletions

View File

@ -0,0 +1,25 @@
/**
* An interface that contains options used when initializing a Channel instance.
*/
export interface ChannelOptions {
'grpc.ssl_target_name_override': string;
'grpc.primary_user_agent': string;
'grpc.secondary_user_agent': string;
'grpc.default_authority': string;
'grpc.keepalive_time_ms': number;
'grpc.keepalive_timeout_ms': number;
[key: string]: string|number;
}
/**
* This is for checking provided options at runtime. This is an object for
* easier membership checking.
*/
export const recognizedOptions = {
'grpc.ssl_target_name_override': true,
'grpc.primary_user_agent': true,
'grpc.secondary_user_agent': true,
'grpc.default_authority': true,
'grpc.keepalive_time_ms': true,
'grpc.keepalive_timeout_ms': true
};

View File

@ -14,6 +14,7 @@ import {FilterStackFactory} from './filter-stack';
import {Metadata, MetadataObject} from './metadata';
import {MetadataStatusFilterFactory} from './metadata-status-filter';
import { Http2SubChannel } from './subchannel';
import {ChannelOptions, recognizedOptions} from './channel-options';
const {version: clientVersion} = require('../../package');
@ -35,19 +36,6 @@ const {
HTTP2_HEADER_USER_AGENT
} = http2.constants;
/**
* An interface that contains options used when initializing a Channel instance.
*/
export interface ChannelOptions {
'grpc.ssl_target_name_override': string;
'grpc.primary_user_agent': string;
'grpc.secondary_user_agent': string;
'grpc.default_authority': string;
'grpc.keepalive_time_ms': number;
'grpc.keepalive_timeout_ms': number;
[key: string]: string|number;
}
export enum ConnectivityState {
CONNECTING,
READY,
@ -212,6 +200,13 @@ export class Http2Channel extends EventEmitter implements Channel {
address: string, readonly credentials: ChannelCredentials,
private readonly options: Partial<ChannelOptions>) {
super();
for (let option in options) {
if (options.hasOwnProperty(option)) {
if (!recognizedOptions.hasOwnProperty(option)) {
console.warn(`Unrecognized channel argument '${option}' will be ignored.`);
}
}
}
if (credentials.isSecure()) {
this.target = new url.URL(`https://${address}`);
} else {

View File

@ -3,10 +3,11 @@ import {URL} from 'url';
import {ClientDuplexStream, ClientDuplexStreamImpl, ClientReadableStream, ClientReadableStreamImpl, ClientUnaryCall, ClientUnaryCallImpl, ClientWritableStream, ClientWritableStreamImpl, ServiceError} from './call';
import {CallOptions, CallStream, StatusObject, WriteObject} from './call-stream';
import {Channel, ChannelOptions, Http2Channel} from './channel';
import {Channel, Http2Channel} from './channel';
import {ChannelCredentials} from './channel-credentials';
import {Status} from './constants';
import {Metadata} from './metadata';
import {ChannelOptions} from './channel-options';
// This symbol must be exported (for now).
// See: https://github.com/Microsoft/TypeScript/issues/20080

View File

@ -1,7 +1,7 @@
import * as _ from 'lodash';
import {CallOptions} from './call-stream';
import {ChannelOptions} from './channel';
import {ChannelOptions} from './channel-options';
import {ChannelCredentials} from './channel-credentials';
import {Client, UnaryCallback} from './client';
import {Metadata} from './metadata';

View File

@ -5,7 +5,7 @@ import { EventEmitter } from "events";
import { Metadata } from "./metadata";
import { CallStream, CallOptions, Http2CallStream } from "./call-stream";
import { EmitterAugmentation1, EmitterAugmentation0 } from "./events";
import { ChannelOptions } from './channel';
import { ChannelOptions } from './channel-options';
const {
HTTP2_HEADER_AUTHORITY,