[Backport 7.x] Force lowercase in all headers (#1195)
This commit is contained in:
committed by
GitHub
parent
11951fe8fc
commit
15a9479a81
@ -34,9 +34,9 @@ class Transport {
|
||||
this.suggestCompression = opts.suggestCompression === true
|
||||
this.compression = opts.compression || false
|
||||
this.headers = Object.assign({},
|
||||
{ 'User-Agent': userAgent },
|
||||
opts.suggestCompression === true ? { 'Accept-Encoding': 'gzip,deflate' } : null,
|
||||
opts.headers
|
||||
{ 'user-agent': userAgent },
|
||||
opts.suggestCompression === true ? { 'accept-encoding': 'gzip,deflate' } : null,
|
||||
lowerCaseHeaders(opts.headers)
|
||||
)
|
||||
this.sniffInterval = opts.sniffInterval
|
||||
this.sniffOnConnectionFault = opts.sniffOnConnectionFault
|
||||
@ -243,10 +243,10 @@ class Transport {
|
||||
})
|
||||
}
|
||||
|
||||
const headers = Object.assign({}, this.headers, options.headers)
|
||||
const headers = Object.assign({}, this.headers, lowerCaseHeaders(options.headers))
|
||||
|
||||
if (options.opaqueId !== undefined) {
|
||||
headers['X-Opaque-Id'] = this.opaqueIdPrefix !== null
|
||||
headers['x-opaque-id'] = this.opaqueIdPrefix !== null
|
||||
? this.opaqueIdPrefix + options.opaqueId
|
||||
: options.opaqueId
|
||||
}
|
||||
@ -262,7 +262,7 @@ class Transport {
|
||||
}
|
||||
|
||||
if (params.body !== '') {
|
||||
headers['Content-Type'] = headers['Content-Type'] || 'application/json'
|
||||
headers['content-type'] = headers['content-type'] || 'application/json'
|
||||
}
|
||||
|
||||
// handle ndjson body
|
||||
@ -277,7 +277,7 @@ class Transport {
|
||||
params.body = params.bulkBody
|
||||
}
|
||||
if (params.body !== '') {
|
||||
headers['Content-Type'] = headers['Content-Type'] || 'application/x-ndjson'
|
||||
headers['content-type'] = headers['content-type'] || 'application/x-ndjson'
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,7 +301,7 @@ class Transport {
|
||||
if (params.body !== '' && params.body != null) {
|
||||
if (isStream(params.body) === true) {
|
||||
if (compression === 'gzip') {
|
||||
params.headers['Content-Encoding'] = compression
|
||||
params.headers['content-encoding'] = compression
|
||||
params.body = params.body.pipe(createGzip())
|
||||
}
|
||||
makeRequest()
|
||||
@ -311,13 +311,13 @@ class Transport {
|
||||
if (err) {
|
||||
return callback(err, result)
|
||||
}
|
||||
params.headers['Content-Encoding'] = compression
|
||||
params.headers['Content-Length'] = '' + Buffer.byteLength(buffer)
|
||||
params.headers['content-encoding'] = compression
|
||||
params.headers['content-length'] = '' + Buffer.byteLength(buffer)
|
||||
params.body = buffer
|
||||
makeRequest()
|
||||
})
|
||||
} else {
|
||||
params.headers['Content-Length'] = '' + Buffer.byteLength(params.body)
|
||||
params.headers['content-length'] = '' + Buffer.byteLength(params.body)
|
||||
makeRequest()
|
||||
}
|
||||
} else {
|
||||
@ -453,5 +453,21 @@ function generateRequestId () {
|
||||
return (nextReqId = (nextReqId + 1) & maxInt)
|
||||
}
|
||||
}
|
||||
|
||||
function lowerCaseHeaders (oldHeaders) {
|
||||
if (oldHeaders == null) return oldHeaders
|
||||
const newHeaders = {}
|
||||
for (const header in oldHeaders) {
|
||||
newHeaders[header.toLowerCase()] = oldHeaders[header]
|
||||
}
|
||||
return newHeaders
|
||||
}
|
||||
|
||||
module.exports = Transport
|
||||
module.exports.internals = { defaultNodeFilter, roundRobinSelector, randomSelector, generateRequestId }
|
||||
module.exports.internals = {
|
||||
defaultNodeFilter,
|
||||
roundRobinSelector,
|
||||
randomSelector,
|
||||
generateRequestId,
|
||||
lowerCaseHeaders
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user