X-Opaque-Id support (#997)
* Added X-Opaque-Id support * Updated type definitions * Updated test * Updated docs
This commit is contained in:
committed by
GitHub
parent
1e1252383d
commit
0f1746014c
3
lib/Transport.d.ts
vendored
3
lib/Transport.d.ts
vendored
@ -38,6 +38,7 @@ interface TransportOptions {
|
||||
headers?: anyObject;
|
||||
generateRequestId?: generateRequestIdFn;
|
||||
name: string;
|
||||
opaqueIdPrefix?: string;
|
||||
}
|
||||
|
||||
export interface RequestEvent<T = any, C = any> {
|
||||
@ -90,6 +91,7 @@ export interface TransportRequestOptions {
|
||||
id?: any;
|
||||
context?: any;
|
||||
warnings?: [string];
|
||||
opaqueId?: string;
|
||||
}
|
||||
|
||||
export interface TransportRequestCallback {
|
||||
@ -121,6 +123,7 @@ export default class Transport {
|
||||
compression: 'gzip' | false;
|
||||
sniffInterval: number;
|
||||
sniffOnConnectionFault: boolean;
|
||||
opaqueIdPrefix: string | null;
|
||||
sniffEndpoint: string;
|
||||
_sniffEnabled: boolean;
|
||||
_nextSniff: number;
|
||||
|
||||
@ -41,6 +41,7 @@ class Transport {
|
||||
this.sniffEndpoint = opts.sniffEndpoint
|
||||
this.generateRequestId = opts.generateRequestId || generateRequestId()
|
||||
this.name = opts.name
|
||||
this.opaqueIdPrefix = opts.opaqueIdPrefix
|
||||
|
||||
this.nodeFilter = opts.nodeFilter || defaultNodeFilter
|
||||
if (typeof opts.nodeSelector === 'function') {
|
||||
@ -114,6 +115,12 @@ class Transport {
|
||||
// TODO: make this assignment FAST
|
||||
const headers = Object.assign({}, this.headers, options.headers)
|
||||
|
||||
if (options.opaqueId !== undefined) {
|
||||
headers['X-Opaque-Id'] = this.opaqueIdPrefix !== null
|
||||
? this.opaqueIdPrefix + options.opaqueId
|
||||
: options.opaqueId
|
||||
}
|
||||
|
||||
// handle json body
|
||||
if (params.body != null) {
|
||||
if (shouldSerialize(params.body) === true) {
|
||||
|
||||
Reference in New Issue
Block a user