Skip to content

Commit

Permalink
feat: Added support for x-www-authenticate header (#533)
Browse files Browse the repository at this point in the history
support both headers for digestAuth: www-authenticate and
x-www-authenticate

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## 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.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
neogermi authored Sep 14, 2024
1 parent d9bf314 commit d52a3e0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d52a3e0

Please # to comment.