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

Support @ResponseStatus with RedirectView [SPR-13197] #17789

Closed
spring-projects-issues opened this issue Jul 4, 2015 · 7 comments
Closed

Support @ResponseStatus with RedirectView [SPR-13197] #17789

spring-projects-issues opened this issue Jul 4, 2015 · 7 comments

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Jul 4, 2015

Christopher Smith opened SPR-13197 and commented

This is a duplicate of #10812, which was closed by allowing a programmatic setting of the response code on the RedirectView object. It would be convenient to be able to set this with @ResponseStatus on the controller method if this is practical.


Affects: 4.2 RC2

Issue Links:

  • #10812 @ResponseStatus annotation is ignored in an @Controller redirect (RedirectView)
  • #17800 Make RedirectViews use RESPONSE_STATUS_ATTRIBUTE as a response status if defined
  • #18019 Document that @ResponseStatus overrides redirect views

Referenced from: commits spring-projects/spring-framework-issues@6521f15

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 6, 2015

Rossen Stoyanchev commented

I'm pretty sure that @ResponseStatus works with redirects. This is done through a request attribute View.RESPONSE_STATUS_ATTRIBUTE. Does it not work?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 6, 2015

Christopher Smith commented

I can confirm that it does not work with the RedirectView object as of 4.2 RC2.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 6, 2015

Rossen Stoyanchev commented

Can you provide a sample controller method of what you're using?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 6, 2015

Christopher Smith commented

Both of these controller methods produced 302s:

    @RequestMapping("about/benefits")
    @ResponseStatus(HttpStatus.MOVED_PERMANENTLY)
    def aboutBenefitsRedirect() {
        new RedirectView('/about/portfolios')
    }

    @RequestMapping("about/test")
    @ResponseStatus(HttpStatus.MOVED_PERMANENTLY)
    def testRedirect() {
        'redirect:/about/portfolios'
    }
@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 6, 2015

Rossen Stoyanchev commented

If you look in RedirectView in the method getHttp11StatusCode it clearly checks the value from @ResponseStatus. However you must ensure that http10Compatible=false (true by default). I've added a repro project that demonstrates this. You configuration may be a little different but this should give you an idea.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 6, 2015

Christopher Smith commented

Aha. With HTTP/2 now a thing, might it be time to change the default to false?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 7, 2015

Brian Clozel commented

Good idea Christopher Smith!
We've created #17800 to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.