Skip to content
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

Closed
juanmbellini opened this issue Jul 23, 2019 · 4 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@juanmbellini
Copy link

Javadoc of ServerHttpRequest.Builder clearly says:

which is part of the header(String, String) method (signature can be seen below).

/**
 * Set or override the specified header.
 */
Builder header(String key, String value);

but the default implementation (DefaultServerHttpRequestBuilder) uses an instance of HttpHeaders, which internally uses a MultiValueMap<String, String> to store headers. So, calling the said method does not override the header, but adds it in the MultiValueMap.

Check the following links:

final MultiValueMap<String, String> headers;

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 23, 2019
@sbrannen sbrannen added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Jul 23, 2019
@sbrannen
Copy link
Member

Thanks for pointing out that inconsistency. We'll look into it.

@sbrannen
Copy link
Member

Related commit: a1ae9ac

@bclozel
Copy link
Member

bclozel commented Jul 23, 2019

We should fix the javadoc since this method is only about adding a header value.
Developers can mutate existing headers with headers(Consumer<HttpHeaders> headersConsumer).

@rstoyanchev
Copy link
Contributor

rstoyanchev commented Jul 23, 2019

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.

@sbrannen sbrannen removed the status: backported An issue that has been backported to maintenance branches label Jul 23, 2019
@sbrannen sbrannen changed the title Inconsistent javadoc: implementation of ServerHttpRequest.Builder (implementation is DefaultServerHttpRequestBuilder) does not override headers In contrast to the Javadoc, ServerHttpRequest.Builder implementation does not override headers Jul 23, 2019
@sbrannen sbrannen added type: enhancement A general enhancement and removed type: documentation A documentation task labels Jul 24, 2019
sbrannen added a commit that referenced this issue Jul 25, 2019
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants