* Fix case-insensitive pre-auth header check in doPing HTTP headers are case-insensitive per RFC 7230, but the pre-auth rejection check accessed x-reject-reason using an exact lowercase key. Servers/proxies may return varying cases (e.g. X-Reject-Reason). Add a getResponseHeader utility for case-insensitive lookup and use it in both pre-auth check paths. * Address PR feedback: optimize getResponseHeader and fix test description Try exact match and lowercase match before falling back to a full scan to avoid array allocation on every call. Fix test description to say "uppercase" instead of "mixed case" to match the test data.
23 lines
685 B
TypeScript
23 lines
685 B
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
export function getResponseHeader(headers: Record<string, string> | undefined, name: string): string | undefined {
|
|
if (!headers) {
|
|
return undefined;
|
|
}
|
|
const direct = headers[name];
|
|
if (direct !== undefined) {
|
|
return direct;
|
|
}
|
|
const lowerName = name.toLowerCase();
|
|
const lowerDirect = headers[lowerName];
|
|
if (lowerDirect !== undefined) {
|
|
return lowerDirect;
|
|
}
|
|
for (const key in headers) {
|
|
if (key.toLowerCase() === lowerName) {
|
|
return headers[key];
|
|
}
|
|
}
|
|
return undefined;
|
|
}
|