mirror of https://github.com/grpc/grpc-node.git
Merge pull request #500 from murgatroid99/pure_js_channel_args_warning
Pure JS: add warnings for unhandled channel options
This commit is contained in:
commit
0ec9fed4bb
|
|
@ -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
|
||||||
|
};
|
||||||
|
|
@ -14,6 +14,7 @@ import {FilterStackFactory} from './filter-stack';
|
||||||
import {Metadata, MetadataObject} from './metadata';
|
import {Metadata, MetadataObject} from './metadata';
|
||||||
import {MetadataStatusFilterFactory} from './metadata-status-filter';
|
import {MetadataStatusFilterFactory} from './metadata-status-filter';
|
||||||
import { Http2SubChannel } from './subchannel';
|
import { Http2SubChannel } from './subchannel';
|
||||||
|
import {ChannelOptions, recognizedOptions} from './channel-options';
|
||||||
|
|
||||||
const {version: clientVersion} = require('../../package');
|
const {version: clientVersion} = require('../../package');
|
||||||
|
|
||||||
|
|
@ -35,19 +36,6 @@ const {
|
||||||
HTTP2_HEADER_USER_AGENT
|
HTTP2_HEADER_USER_AGENT
|
||||||
} = http2.constants;
|
} = 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 {
|
export enum ConnectivityState {
|
||||||
CONNECTING,
|
CONNECTING,
|
||||||
READY,
|
READY,
|
||||||
|
|
@ -212,6 +200,13 @@ export class Http2Channel extends EventEmitter implements Channel {
|
||||||
address: string, readonly credentials: ChannelCredentials,
|
address: string, readonly credentials: ChannelCredentials,
|
||||||
private readonly options: Partial<ChannelOptions>) {
|
private readonly options: Partial<ChannelOptions>) {
|
||||||
super();
|
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()) {
|
if (credentials.isSecure()) {
|
||||||
this.target = new url.URL(`https://${address}`);
|
this.target = new url.URL(`https://${address}`);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,11 @@ import {URL} from 'url';
|
||||||
|
|
||||||
import {ClientDuplexStream, ClientDuplexStreamImpl, ClientReadableStream, ClientReadableStreamImpl, ClientUnaryCall, ClientUnaryCallImpl, ClientWritableStream, ClientWritableStreamImpl, ServiceError} from './call';
|
import {ClientDuplexStream, ClientDuplexStreamImpl, ClientReadableStream, ClientReadableStreamImpl, ClientUnaryCall, ClientUnaryCallImpl, ClientWritableStream, ClientWritableStreamImpl, ServiceError} from './call';
|
||||||
import {CallOptions, CallStream, StatusObject, WriteObject} from './call-stream';
|
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 {ChannelCredentials} from './channel-credentials';
|
||||||
import {Status} from './constants';
|
import {Status} from './constants';
|
||||||
import {Metadata} from './metadata';
|
import {Metadata} from './metadata';
|
||||||
|
import {ChannelOptions} from './channel-options';
|
||||||
|
|
||||||
// This symbol must be exported (for now).
|
// This symbol must be exported (for now).
|
||||||
// See: https://github.com/Microsoft/TypeScript/issues/20080
|
// See: https://github.com/Microsoft/TypeScript/issues/20080
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
import {CallOptions} from './call-stream';
|
import {CallOptions} from './call-stream';
|
||||||
import {ChannelOptions} from './channel';
|
import {ChannelOptions} from './channel-options';
|
||||||
import {ChannelCredentials} from './channel-credentials';
|
import {ChannelCredentials} from './channel-credentials';
|
||||||
import {Client, UnaryCallback} from './client';
|
import {Client, UnaryCallback} from './client';
|
||||||
import {Metadata} from './metadata';
|
import {Metadata} from './metadata';
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { EventEmitter } from "events";
|
||||||
import { Metadata } from "./metadata";
|
import { Metadata } from "./metadata";
|
||||||
import { CallStream, CallOptions, Http2CallStream } from "./call-stream";
|
import { CallStream, CallOptions, Http2CallStream } from "./call-stream";
|
||||||
import { EmitterAugmentation1, EmitterAugmentation0 } from "./events";
|
import { EmitterAugmentation1, EmitterAugmentation0 } from "./events";
|
||||||
import { ChannelOptions } from './channel';
|
import { ChannelOptions } from './channel-options';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
HTTP2_HEADER_AUTHORITY,
|
HTTP2_HEADER_AUTHORITY,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue