Skip to content

Conversation

mieseprem
Copy link

Does it fix #35576 ?

If that's the case: here you go — enjoy

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 8, 2025
Signed-off-by: Clemens Nafe <clemens.nafe@otto.de>
*/
public B header(String name, Object... values) {
this.headers.addAll(name, Arrays.asList(values));
this.headers.addAll(name, Arrays.stream(values).map(String::valueOf).toList());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MultiValueMap<String, Object> matches to how MockHttpServletRequest manages header values, allowing Collections, arrays, as well as date and number values, which it then formats when headers are obtained. So this change is unlikely to go without causing regressions.

The code in this method could match the behavior of getDateHeader and getIntHeader of MockHttpServletRequest, in reverse by formatting to String values in the same way, to ensure backwards compatibility.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid heading in the wrong direction, I’ll briefly confirm what I’ve understood:

Working internally with HttpHeaders isn’t the best idea because of potential regressions. It’s better to continue using MultiValueMap internally.

So, if we still want to offer a method headers(Consumer<HttpHeaders>), we should consume the HttpHeaders and then call the existing headers(HttpHeaders) method. I can change it in that direction.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if we still want to offer a method headers(Consumer<HttpHeaders>), we should consume the HttpHeaders and then call the existing headers(HttpHeaders) method.

That unfortunately does not work.

If you create a new instance of HttpHeaders and provide that to the Consumer<HttpHeaders>, the consumer can only add new headers. It cannot remove or process existing headers.

@rstoyanchev rstoyanchev added in: test Issues in the test module type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 9, 2025
@rstoyanchev rstoyanchev added this to the 7.0.0-RC1 milestone Oct 9, 2025
@rstoyanchev rstoyanchev changed the title Add method to provide headers via consumer MockMvc request builders should expose HttpHeaders Oct 9, 2025
Signed-off-by: Clemens Nafe <clemens.nafe@otto.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: test Issues in the test module type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow HttpHeaders invocation on MockHttpServletRequest and MockHttpServletRequestBuilder

4 participants