Issue: Unable to Set Status on RedirectView
in Rendering.Builder
Description
In the current implementation of the Rendering.Builder
in Spring WebFlux, it is not possible to set the status code on the RedirectView
when using the redirectTo
method. This limitation makes the status
method on the Rendering.Builder
ineffective for redirects, as the status code is not propagated to the RedirectView
.
Steps to Reproduce
- Create a Spring WebFlux controller that returns a
Mono<Rendering>
. - Use the
Rendering.redirectTo("url").status(HttpStatus.NOT_FOUND).build()
method to create a redirect response. - Observe that the status code on the
RedirectView
is not set toHttpStatus.NOT_FOUND
.
Expected Behavior
The status code set on the Rendering.Builder
should be propagated to the RedirectView
, ensuring that the redirect response has the correct status code.
Actual Behavior
The status code is only set on the Rendering
object and not on the RedirectView
, resulting in the default status code being used for the redirect.
Proposed Solution
Modify the DefaultRenderingBuilder
class to set the status code on the RedirectView
when the status
method is called. Here is the proposed change:
@Override
public DefaultRenderingBuilder status(HttpStatusCode status) {
this.status = status;
if (this.view instanceof RedirectView) {
((RedirectView) this.view).setStatusCode(status);
}
return this;
}
With this change, the status code set on the Rendering.Builder
will also be applied to the RedirectView
.
Environment
- Spring WebFlux Version: 6.1.6
- Java Version: 21
Additional Context
This issue affects any application using Spring WebFlux that relies on setting custom status codes for redirects. The proposed solution ensures consistency and correctness in the HTTP response status for redirects.