Search code examples
javaspringspring-webfluxhttp-status-codes

how to set non-standard HttpStatus in Spring reactive's ServerHttpResponse?


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)

Any suggestions on how to set the status otherwise ?


Solution

  • After creating an issue in Github. I was made aware that we can downcast the Interface to AbstractServerHttpResponse in order to get access to the setStatusCodeValue method that takes an Integer as a parameter and thus enables us to set non-standard statuses.

    Also, the Spring team may consider exposing this method in the ServerHttpResponse interface for future releases.