Skip to content

fix: answer digest challenges with the caller's request - #616

Merged
Mzack9999 merged 1 commit into
dwisiswant0/fix/apply-digest-auth-to-the-http-2-fallbackfrom
dwisiswant0/fix/answer-digest-challenges-with-the-callers-request
Oct 26, 2026
Merged

Mzack9999 merged 1 commit into
dwisiswant0/fix/apply-digest-auth-to-the-http-2-fallbackfrom
dwisiswant0/fix/answer-digest-challenges-with-the-callers-request

Conversation

@dwisiswant0

Copy link
Copy Markdown
Member

send passed DigestAuth requests to go-http-digest-auth-client, whose RoundTrip builds new requests from the method, URL, body, and User-Agent alone. Every other header, the request context (deadline, cancellation, and httptrace hooks), and fields such as Host were lost.

For digest auth, send now sends a clone of the caller's request and, on a 401 with a Digest challenge, a second clone with an Authorization header added. Both clones read a copy of the body, because a server that rejects a large body may stop reading it partway and would leave req.Body unusable for the second request and for retries.

The library can't compute the header on its own, so this adds a small RFC 7616 client (MD5, SHA-256, and SHA-512-256, their -sess variants, auth and auth-int, and userhash) that also reads several challenges from one WWW-Authenticate value, and drops the dependency. When no challenge can be answered, the caller gets the server's 401 response unchanged.

Fixes: #614
Refs: #613

send passed DigestAuth requests to go-http-digest-auth-client, whose
RoundTrip builds new requests from the method, URL, body, and
User-Agent alone. Every other header, the request context (deadline,
cancellation, and httptrace hooks), and fields such as Host were lost.

For digest auth, send now sends a clone of the caller's request and,
on a 401 with a Digest challenge, a second clone with an Authorization
header added. Both clones read a copy of the body, because a server
that rejects a large body may stop reading it partway and would leave
req.Body unusable for the second request and for retries.

The library can't compute the header on its own, so this adds a small
RFC 7616 client (MD5, SHA-256, and SHA-512-256, their -sess variants,
auth and auth-int, and userhash) that also reads several challenges
from one WWW-Authenticate value, and drops the dependency. When no
challenge can be answered, the caller gets the server's 401 response
unchanged.

Fixes: #614
Refs: #613
Signed-off-by: Dwi Siswanto <git@dw1.io>
@dwisiswant0
dwisiswant0 requested a review from Mzack9999 October 26, 2026 14:54
@dwisiswant0
dwisiswant0 added this pull request to stack #617 October 26, 2026 14:54
@dwisiswant0

Copy link
Copy Markdown
Member Author

Stacked.

@Mzack9999
Mzack9999 merged commit f079b0d into main Oct 26, 2026
7 checks passed
@Mzack9999
Mzack9999 deleted the dwisiswant0/fix/answer-digest-challenges-with-the-callers-request branch October 26, 2026 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DigestAuth drops request headers, cancellation, and tracing

2 participants