mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Preserve case of user-provided http headers in request node
Fixes #3081
This commit is contained in:
@@ -171,8 +171,23 @@ in your Node-RED user directory (${RED.settings.userDir}).
|
||||
opts.timeout = msg.requestTimeout;
|
||||
}
|
||||
}
|
||||
const originalHeaderMap = {};
|
||||
|
||||
opts.hooks = {
|
||||
beforeRequest: [
|
||||
options => {
|
||||
// Whilst HTTP headers are meant to be case-insensitive,
|
||||
// in the real world, there are servers that aren't so compliant.
|
||||
// GOT will lower case all headers given a chance, so we need
|
||||
// to restore the case of any headers the user has set.
|
||||
Object.keys(options.headers).forEach(h => {
|
||||
if (originalHeaderMap[h] && originalHeaderMap[h] !== h) {
|
||||
options.headers[originalHeaderMap[h]] = options.headers[h];
|
||||
delete options.headers[h];
|
||||
}
|
||||
})
|
||||
}
|
||||
],
|
||||
beforeRedirect: [
|
||||
(options, response) => {
|
||||
let redirectInfo = {
|
||||
@@ -283,7 +298,7 @@ in your Node-RED user directory (${RED.settings.userDir}).
|
||||
})
|
||||
if (normalisedHeaders['www-authenticate']) {
|
||||
let authHeader = buildDigestHeader(digestCreds.user,digestCreds.password, options.method, requestUrl.pathname, normalisedHeaders['www-authenticate'])
|
||||
options.headers.authorization = authHeader;
|
||||
options.headers.Authorization = authHeader;
|
||||
}
|
||||
sentCreds = true;
|
||||
return retry(options);
|
||||
@@ -439,6 +454,14 @@ in your Node-RED user directory (${RED.settings.userDir}).
|
||||
opts.https = { rejectUnauthorized: msg.rejectUnauthorized };
|
||||
}
|
||||
}
|
||||
|
||||
// Now we have established all of our own headers, take a snapshot
|
||||
// of their case so we can restore it prior to the request being sent.
|
||||
if (opts.headers) {
|
||||
Object.keys(opts.headers).forEach(h => {
|
||||
originalHeaderMap[h.toLowerCase()] = h
|
||||
})
|
||||
}
|
||||
got(url,opts).then(res => {
|
||||
msg.statusCode = res.statusCode;
|
||||
msg.headers = res.headers;
|
||||
|
Reference in New Issue
Block a user