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

Allow non-standard HttpStatus in reactive ServerHttpResponse #24400

Closed
saad14092 opened this issue Jan 20, 2020 · 5 comments
Closed

Allow non-standard HttpStatus in reactive ServerHttpResponse #24400

saad14092 opened this issue Jan 20, 2020 · 5 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@saad14092
Copy link

Affects: 5.2.1.RELEASE

in org.springframework.http.server.reactive.ServerHttpResponse we have the following method :

boolean setStatusCode(@Nullable HttpStatus status);
that is supposed to allow us to set the http status code for the response. The problem is that we can't use a simple int value and we have to pass through HttpStatus that cannot resolve non-standard Http status codes (498 in my case)

I've already asked on SO and apparently there is no way to make this work in the current release ?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 20, 2020
@rstoyanchev rstoyanchev self-assigned this Jan 20, 2020
@rstoyanchev rstoyanchev added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Jan 20, 2020
@rstoyanchev
Copy link
Contributor

An @Controller can set the status to an integer value via ResponseEntity#status(int) and a HandlerFunction can do the same use ServerResponse#status(int). Does either of those work for your case?

@rstoyanchev rstoyanchev added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 20, 2020
@saad14092
Copy link
Author

@rstoyanchev I don't think so. I need to set the status code in a org.springframework.web.server.WebFilter

Which has a method WebFilter#filter(ServerWebExchange ex, WebFilterChain chain)
and ex.getResponse() returns a ServerHttpResponse

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jan 20, 2020
@jhoeller
Copy link
Contributor

Note that a pair of plain status accessors is available on AbstractServerHttpResponse: namely setStatusCodeValue and getStatusCodeValue. We could consider exposing them on the interface as well. For the time being, feel free to downcast accordingly.

@jhoeller jhoeller added the type: enhancement A general enhancement label Jan 20, 2020
@saad14092
Copy link
Author

@jhoeller Thanks for the tip. That should do the trick for the time being.

@rstoyanchev rstoyanchev removed the status: feedback-provided Feedback has been provided label Jan 29, 2020
@rstoyanchev rstoyanchev added this to the 5.2.4 milestone Jan 29, 2020
@rstoyanchev rstoyanchev changed the title Cannot set non-standard HttpStatus in Spring reactive's ServerHttpResponse Allow non-standard HttpStatus in reactive ServerHttpResponse Jan 29, 2020
@rstoyanchev
Copy link
Contributor

Since this is now used as unofficial API (case here and also in Boot), we need to make sure setStatusCodeValue is protected against being set after response is committed. It would also make it consistent with the programming models (annotation and functional) as well as with ClientHttpResponse

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants