From d52a3e0b32db305e7839af2aa8464201319c0504 Mon Sep 17 00:00:00 2001 From: Sebastian Germesin <633833+neogermi@users.noreply.github.com> Date: Sat, 14 Sep 2024 07:35:58 +0200 Subject: [PATCH] feat: Added support for x-www-authenticate header (#533) support both headers for digestAuth: www-authenticate and x-www-authenticate ## Summary by CodeRabbit - **Bug Fixes** - Enhanced handling of HTTP 401 Unauthorized responses to support both `www-authenticate` and `x-www-authenticate` headers for improved authentication robustness. --- src/HttpClient.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/HttpClient.ts b/src/HttpClient.ts index 8852588..a0b44bf 100644 --- a/src/HttpClient.ts +++ b/src/HttpClient.ts @@ -546,10 +546,10 @@ export class HttpClient extends EventEmitter { } let response = await undiciRequest(requestUrl, requestOptions as UndiciRequestOption); - if (response.statusCode === 401 && response.headers['www-authenticate'] && + if (response.statusCode === 401 && (response.headers['www-authenticate'] || response.headers['x-www-authenticate']) && !requestOptions.headers.authorization && args.digestAuth) { // handle digest auth - const authenticateHeaders = response.headers['www-authenticate']; + const authenticateHeaders = response.headers['www-authenticate'] ?? response.headers['x-www-authenticate']; const authenticate = Array.isArray(authenticateHeaders) ? authenticateHeaders.find(authHeader => authHeader.startsWith('Digest ')) : authenticateHeaders;