You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
curl -v 'http://localhost:8080/responseEntity'
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET /responseEntity HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Cache-Control: max-age=3600
< Content-Type: text/plain;charset=UTF-8
< Content-Length: 21
<
* Connection #0 to host localhost left intact
supposed to be cached* Closing connection 0
curl -v 'http://localhost:8080/serverResponse'
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET /serverResponse HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Cache-Control: no-cache
< Content-Type: text/plain;charset=UTF-8
< Content-Length: 21
<
* Connection #0 to host localhost left intact
supposed to be cached* Closing connection 0
As we can see the /responseEntity endpoint returns max-age=3600 for our Cache-Control header. However, /serverResponse returns no-cache. ResponseEntityResultHandler seems to be overriding existing headers and DefaultServerResponseBuilder not to.
I think the headers from the handler should take precedence since it is the main and most specific request handling logic vs a filter which is applies to many requests. A handler can also check for the presence of existing header values if it really needs to, while in the opposite case it would have no way of overriding existing header values.
@poutsma maybe this is something that needs to be adjusted in WebFlux.fn?
rstoyanchev
changed the title
ResponseEntityResultHandler and ServerResponseResultHandler have different behavior regarding already present headers
ResponseEntityResultHandler and ServerResponseResultHandler behave differently with regards to already present response headers
Nov 29, 2021
poutsma
changed the title
ResponseEntityResultHandler and ServerResponseResultHandler behave differently with regards to already present response headers
WebFlux ServerResponse does not overwrite already present response headers
Nov 30, 2021
It seems like ResponseEntityResultHandler behaves differently compared to ServerResponseResultHandler regarding their handling of already present HTTP headers.
For example: Github
Testing using
curl
:As we can see the
/responseEntity
endpoint returnsmax-age=3600
for our Cache-Control header. However,/serverResponse
returnsno-cache
.ResponseEntityResultHandler seems to be overriding existing headers and DefaultServerResponseBuilder not to.
spring-framework/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandler.java
Lines 150 to 155 in 2f32806
spring-framework/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilder.java
Lines 362 to 368 in 2f32806
The fix might be trivial, but maybe the intended behavior should be discussed.
The text was updated successfully, but these errors were encountered: