Handle headers as request option
This commit is contained in:
5
lib/Transport.d.ts
vendored
5
lib/Transport.d.ts
vendored
@ -38,11 +38,16 @@ export interface SniffMeta {
|
||||
reason: string;
|
||||
}
|
||||
|
||||
declare type anyObject = {
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
export interface RequestOptions {
|
||||
ignore?: number | number[];
|
||||
requestTimeout?: number | string;
|
||||
maxRetries?: number;
|
||||
asStream?: boolean;
|
||||
headers?: anyObject;
|
||||
}
|
||||
|
||||
export default class Transport {
|
||||
|
||||
@ -74,7 +74,7 @@ class Transport {
|
||||
return callback(new NoLivingConnectionsError('There are not living connections'), result)
|
||||
}
|
||||
|
||||
params.headers = params.headers || {}
|
||||
const headers = options.headers || {}
|
||||
// handle json body
|
||||
if (params.body != null) {
|
||||
if (shouldSerialize(params.body) === true) {
|
||||
@ -84,9 +84,9 @@ class Transport {
|
||||
return callback(err, result)
|
||||
}
|
||||
}
|
||||
params.headers['Content-Type'] = 'application/json'
|
||||
headers['Content-Type'] = 'application/json'
|
||||
if (isStream(params.body) === false) {
|
||||
params.headers['Content-Length'] = '' + Buffer.byteLength(params.body)
|
||||
headers['Content-Length'] = '' + Buffer.byteLength(params.body)
|
||||
}
|
||||
// handle ndjson body
|
||||
} else if (params.bulkBody != null) {
|
||||
@ -99,16 +99,17 @@ class Transport {
|
||||
} else {
|
||||
params.body = params.bulkBody
|
||||
}
|
||||
params.headers['Content-Type'] = 'application/x-ndjson'
|
||||
headers['Content-Type'] = 'application/x-ndjson'
|
||||
if (isStream(params.body) === false) {
|
||||
params.headers['Content-Length'] = '' + Buffer.byteLength(params.body)
|
||||
headers['Content-Length'] = '' + Buffer.byteLength(params.body)
|
||||
}
|
||||
}
|
||||
|
||||
if (this.suggestCompression === true) {
|
||||
params.headers['Accept-Encoding'] = 'gzip,deflate'
|
||||
headers['Accept-Encoding'] = 'gzip,deflate'
|
||||
}
|
||||
|
||||
params.headers = headers
|
||||
// serializes the querystring
|
||||
params.querystring = this.serializer.qserialize(params.querystring)
|
||||
// handles request timeout
|
||||
|
||||
Reference in New Issue
Block a user