简体   繁体   English

如何在 Spring 反应的 ServerHttpResponse 中设置非标准的 HttpStatus?

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

in org.springframework.http.server.reactive.ServerHttpResponse we have the following method :org.springframework.http.server.reactive.ServerHttpResponse我们有以下方法:

boolean setStatusCode(@Nullable HttpStatus status);

that is supposed to allow us to set the http status code for the response.这应该允许我们为响应设置 http 状态代码。 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)问题是我们不能使用简单的int值,我们必须通过无法解析非标准 Http 状态代码的 HttpStatus(在我的例子中是498

Any suggestions on how to set the status otherwise ?关于如何设置状态的任何建议?

After creating an issue in Github.在 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.我意识到我们可以将接口向下转换为AbstractServerHttpResponse以访问setStatusCodeValue方法,该方法将整数作为参数,从而使我们能够设置非标准状态。

Also, the Spring team may consider exposing this method in the ServerHttpResponse interface for future releases.此外,Spring 团队可能会考虑在ServerHttpResponse接口中公开此方法以供将来发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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