-
Notifications
You must be signed in to change notification settings - Fork 38.1k
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
Deprecate HttpHeaders.writableHttpHeaders #32116
Comments
The Javadoc of
This looks like the expected behavior to me. I am having trouble understanding the report. If the headers are read-only, that's specifically to avoid changing them. If you insist in doing that, it's asking for trouble really. |
I agree that trying to change read-only objects is asking for trouble, which is a general design-flaw with how It looks like the
|
ReadOnlyHttpHeaders
issue with cachedContentType
if Content-Type
is modified via HttpHeaders.writableHttpHeaders()
ReadOnlyHttpHeaders
issue with cachedContentType
if Content-Type
is modified via HttpHeaders.writableHttpHeaders()
Thanks for raising this. If you'd like to mutate the We'll use this issue to deprecate |
I hope the people of the future won't lynch me after the removal breaks their code base and they find this issue 😰 (if someone from the future is reading this, feel free to leave a "👋"). Jokes aside, I feel like there could be a little more support for handling, mutating and testing
Maybe I'm overlooking some mutators but to me it looked like most mutator functionality was only provided for Spring Reactive. |
@m42cel that's interesting feedback. We'll have a look and see if we need to create new issues to help with that. |
Affects: 5.1 / 6.1
What
This problem arises from the fact the Spring allows to remove the
ReadOnlyHttpHeaders
wrapper without creating a modifiable copy but instead modifies the underlyingMultiValueMap
and thereby allows modifying anReadOnlyHttpHeaders
object.When using
ReadOnlyHttpHeaders::getContentType
it will cache the returned Content-Type, which was introduced in Improve WebFlux performance for header management [SPR-17250].However, if the Content-Type of the original
HttpHeaders
object is changed, the cache is not invalidated and a successive call toreadOnlyHttpHeaders.getContentType()
will return the outdated Content-Type, whilereadOnlyHttpHeaders.getFirst(HttpHeaders.CONTENT_TYPE)
will return the new value.Background
With the update from Spring Boot 3.1 to 3.2 many
HttpHeaders
created by Spring Web seem to be changed toReadOnlyHttpHeaders
. This broke many parts of our project, since we often intercept requests to do some modifications (like removing specific headers before forwarding the request to an internal host). Since it's not possible to set a newHttpHeaders
object to aHttpRequest
orHttpServletRequest
we now useHttpHeaders::writableHttpHeaders
method to do modifications of the original headers.This however does not work for the Content-Type once it is cached in the
HttpServletRequest
'sReadOnlyHttpHeaders
.One solution would be to completely wrap the original
HttpRequest
before passing it on in the interceptor chain (which I think is the recommended approach) but that doesn't change the fact that theHttpHeaders::writableHttpHeaders
andcachedContentType
cause some inconsistency.Example
The text was updated successfully, but these errors were encountered: