When mutating a ServerHttpRequest or ClientResponse, the respective
builders no longer access cookies automatically which causes them to
be parsed and does so only if necessary. Likewise re-applying the
read-only HttpHeaders wrapper is avoided.
See gh-24680
Given that the body is a Flux<DataBuffer> there probably could be a
Flux<DataBuffer> body();
At least bodyToFlux(DataBuffer.class) which is used when mutating and
is a common case should not incur overhead.
See gh-24680
from() has the flaw of ignoring the body and it can't be fixed because
applications are guaranteed to be setting it already and if set twice
the builder drains the first body.
mutate() is a better fit in any case for what needs to be done in a
filter chain. It can be done more efficiently and is consistent with
similar options on the server side.
See gh-24680
Motivation
----------
The Spring MVC ModelAttributeMethodProcessor includes many helpful
extension methods that allow developers to extend and enhance the data
binding capabilities of the class. Unfortunately, Spring WebFlux's
equivalent class, the ModelAttributeMethodArgumentResolver, does not
include these same extension methods. I am leveraging these extension
methods, specifically the bindRequestParameters method, to provide
valuable enhancements to my application. I would like to provide these
same enhancements to the WebFlux portion of my application and am
unable to do so at this time. I would like to update the WebFlux
ModelAttributeMethodArgumentResolver to add the bindRequestParameters
method.
Modifications
-------------
I created a new method called bindRequestParameters and encapsulated
the WebExchangeDataBinder bind call inside of it. This method is
marked as protected as it should only be used by children of this
class. This change mirrors the behavior in the equivalent Spring MVC
class (ModelAttributeMethodProcessor).
Result
------
The WebFlux ModelAttributeMethodArgumentResolver can now accept
alternative data binding implementations mirroring the Web MVC
behavior.
This commit changes the way RouterFunctions registered to the builder
are composed in both WebFlux.fn and WebMvc.fn.
Prior to this commit, all routes added to the build were composed with
`reduce`.
After this commit, all routes are stored in a special router function,
allowing for more efficient execution and smaller stack traces.
Closes gh-24652
This commit changes the way two RouterFunctions are composed in
WebFlux.fn. Prior to this commit, two were composed with
`switchIfEmpty()`, switching from the first to the second route if the
first did not provide an element.
After this commit, two router functions are compose using `concat`,
which results in a smaller stack trace.
See gh-24652
This commit adds the checkNotModified method to ServerRequest in both
WebFlux.fn and WebMvc.fn. Unlike other checkNotModified methods found
in the framework, this method does not return a boolean, but rather
a response wrapped in a Mono/Optional. If the resource has
not been changed, the not-modified response can be returned directly;
if the resource has changed, the user can create a corresponding
response using switchIfEmpty/orElse(Get).
Closes gh-24173
The attribute was previously removed only before exception resolution
in the DispatcherServlet in order to allow error rendering to make an
independent choice on content negotation.
However, Boot rendering happens later in an ERROR dispatch which could
also be a nested dispatch on some servers. So the attribute must also
generally be removed prior to mapping.
We also move the methods where this is done to the base
RequestMappingInfoHandlerMapping class which also deals with the
produces condition and where the producible attribute is added in the
first place.
Closes gh-24466
Even thought Tomcat and Jetty, which commit the response more lazily,
were not impacted by this issue, it still makes sense for them to
complete the WebFlux response (and pre-commit actions) at the same time
as for other servers for consistent behavior.
See gh-24475
Prior to this commit, some WebSocket `RequestUpgradeStrategy` reactive
implementations would prevent the application from writing HTTP headers
and cookies to the response.
For Reactor Netty and Undertow, handling the upgrade and starting the
WebSocket communication marks the response status and headers as sent
and the application cannot update HTTP response headers after that.
This commit ensures that the `RequestUpgradeStrategy` implementations
mark the responses as "complete", so that headers are written before we
delegate to the server implementation.
Fixes gh-24475