Skip to content

SPR-15066 - Allow request interceptor to add to headers set via entity #1277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

einarpehrson
Copy link

@einarpehrson einarpehrson commented Dec 29, 2016

Provide a fully mutable HttpHeaders to ClientHttpRequestInterceptors of a RestTemplate when headers are set using HttpEntity. This avoids UnsupportedOperationException if both HttpEntity and ClientHttpRequestInterceptor add values for the same HTTP header.

I came upon this error while investigating a bug report in a third-party starter I maintain. The user was using a RestTemplate where our starter (without the user's knowledge) provided a ClientHttpRequestInterceptor that added an Authorization header. The user rather wanted to use a different authentication method and provided an Authorization header with a different scheme through an HttpEntity passed to the RestTemplate. I am avoiding this problem in our starter by calling HttpHeaders#set(String, String) instead of #add(String, String).

But seeing that HttpEntityRequestCallback was copying over headers from the provided HttpEntity to another HttpHeaders object used for the request, I thought the intended behavior was rather to provide a fully mutable HttpHeaders for the remainder of the processing of the request, including any invocation of ClientHttpRequestInterceptors.

On the other hand, this is a marginal use case at best, and could even be considered misuse of the API.

Issue: SPR-15066

Provide a fully mutable HttpHeaders to ClientHttpRequestInterceptors
of a RestTemplate when headers are set using HttpEntity. This avoids
UnsupportedOperationException if both HttpEntity and
ClientHttpRequestInterceptor add values for the same HTTP header.

Issue: SPR-15066
@pivotal-issuemaster
Copy link

@einarpehrson Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@snicoll snicoll changed the title Allow request interceptor to add to headers set via entity SPR-15066 - Allow request interceptor to add to headers set via entity Dec 29, 2016
@pivotal-issuemaster
Copy link

@einarpehrson Thank you for signing the Contributor License Agreement!

@einarpehrson
Copy link
Author

Declining this PR since @sdeleuze pushed these changes in his commits 554662e and 73a81f9.

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.

3 participants