简体   繁体   中英

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM