-
Notifications
You must be signed in to change notification settings - Fork 38.8k
MockMvc request builders should expose HttpHeaders #35588
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Clemens Nafe <clemens.nafe@otto.de>
4095bc8
to
23d7684
Compare
*/ | ||
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()); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 theHttpHeaders
and then call the existingheaders(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.
Signed-off-by: Clemens Nafe <clemens.nafe@otto.de>
Does it fix #35576 ?
If that's the case: here you go — enjoy