Skip to content
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

Unable to Set Status on RedirectView in Rendering.Builder #33497

Closed
yfoel opened this issue Sep 6, 2024 · 0 comments
Closed

Unable to Set Status on RedirectView in Rendering.Builder #33497

yfoel opened this issue Sep 6, 2024 · 0 comments
Labels
status: superseded An issue that has been superseded by another

Comments

@yfoel
Copy link
Contributor

yfoel commented Sep 6, 2024

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

  1. Create a Spring WebFlux controller that returns a Mono<Rendering>.
  2. Use the Rendering.redirectTo("url").status(HttpStatus.NOT_FOUND).build() method to create a redirect response.
  3. Observe that the status code on the RedirectView is not set to HttpStatus.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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 6, 2024
yfoel added a commit to yfoel/spring-framework that referenced this issue Sep 6, 2024
@rstoyanchev rstoyanchev added status: superseded An issue that has been superseded by another and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 9, 2024
@rstoyanchev rstoyanchev closed this as not planned Won't fix, can't repro, duplicate, stale Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants