Handle headers as request option

This commit is contained in:
delvedor
2018-12-13 16:54:01 +01:00
parent 396686ee77
commit 3c667d38e6
2 changed files with 12 additions and 6 deletions

View File

@ -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