-
Notifications
You must be signed in to change notification settings - Fork 37.9k
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
In contrast to the Javadoc, ServerHttpRequest.Builder implementation does not override headers #23333
Comments
Thanks for pointing out that inconsistency. We'll look into it. |
Related commit: a1ae9ac |
We should fix the javadoc since this method is only about adding a header value. |
It seems unlikely for code to depend on adding a header when mutating a server request. That probably explains the original Javadoc. So I think we should fix the behavior. However to make it a little less disruptive we could add a new method in 5.1.x: /**
* Set or override the specified header value(s).
*/
Builder header(String key, String... value); Then deprecate the existing one in 5.1.x and remove it in 5.2 since having the two side by side is inconsistent and limiting (one adds, the other sets, no way to set with one, etc.), so we don't want a prolonged period of keeping them side by side. |
Prior to this commit, the `header(String, String)` method in the ServerHttpRequest.Builder API actually added a header value instead of setting or overriding a header value. Since this conflicted with the stated behavior in the Javadoc as well as the original intention of the method, we have decided to introduce an overloaded variant `header(String, String...)` which accepts a var-args list of header values to set or override. In addition, this commit deprecates the existing `header(String, String)` method for removal in Spring Framework 5.2. In order not to be a breaking change for custom implementations of the builder API, this commit implements the new `header(String, String...)` method as an interface `default` method, with the intent to remove the default implementation in Spring Framework 5.2 closes gh-23333
Javadoc of
ServerHttpRequest.Builder
clearly says:spring-framework/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequest.java
Line 140 in 5190eaf
which is part of the
header(String, String)
method (signature can be seen below).but the default implementation (
DefaultServerHttpRequestBuilder
) uses an instance ofHttpHeaders
, which internally uses aMultiValueMap<String, String>
to store headers. So, calling the said method does not override the header, but adds it in theMultiValueMap
.Check the following links:
spring-framework/spring-web/src/main/java/org/springframework/http/server/reactive/DefaultServerHttpRequestBuilder.java
Line 48 in 5190eaf
spring-framework/spring-web/src/main/java/org/springframework/http/server/reactive/DefaultServerHttpRequestBuilder.java
Line 115 in 5190eaf
spring-framework/spring-web/src/main/java/org/springframework/http/HttpHeaders.java
Line 417 in 5190eaf
spring-framework/spring-web/src/main/java/org/springframework/http/HttpHeaders.java
Line 1622 in 5190eaf
The text was updated successfully, but these errors were encountered: