Keep configured HTTP headers on the repository origin across redirects - #957
Merged
Merged
Conversation
Fixes apache#956. HttpClient copies the headers of the original request onto every redirected request, so headers configured for a repository through setHttpHeaders or the method configuration followed redirects to other hosts. The wagon now records the repository origin and the configured header names in the request context, and an interceptor on the shared client removes those headers from any request whose target differs from the origin in scheme, host or effective port. User-Agent is exempt. Setting -Dmaven.wagon.http.originScopedHeaders=false restores the previous behaviour.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #956.
Headers configured for a repository (
setHttpHeaders,<httpConfiguration>method headers) were set on every request, and HttpClient's redirect handling copied them onto the redirected request, so a repository that redirected to another host received them there too. Those headers are often credentials.AbstractHttpClientWagonnow puts the repository origin and the configured header names into the per-requestHttpClientContext, and a request interceptor registered once on the shared client,OriginScopedHeadersInterceptor, removes those headers from any request whose target host differs from the origin in scheme, host or effective port. A redirect within the same origin keeps them.User-Agentis exempt, since it identifies the client rather than the repository. Basic authentication through the credentials provider is unchanged; HttpClient already scopes it by host.-Dmaven.wagon.http.originScopedHeaders=falserestores the previous behaviour.Two tests in
HttpWagonTestCasecover a redirect to another origin (header must not arrive) and a redirect within the origin (header must arrive).wagon-http-lightweightfollows redirects insideHttpURLConnectionand cannot apply the same rule; its test class opts out of the two tests and the gap remains documented in #956.Verified:
mvn -pl wagon-providers/wagon-http-shared,wagon-provider-test,wagon-providers/wagon-http -am verify→ green, 60 tests inHttpWagonTest.This change was created with AI assistance.