Affects: \ 5.3.27


At present, HTTP based RPC communication is becoming increasingly mainstream, but in business scenarios, it is a common phenomenon that the corresponding status code is more than the HTTPSTATUS code. Therefore, using existing status codes cannot meet the complex state requirements of the business. We would like to customize some status codes for the 5xx series. But it was found that Spring imposed restrictions when creating the corresponding body, and we were unable to use our own defined status codes? I don't think it's necessary to write the following code section dead, it should be changed to a more flexible extension method.

public interface ServerHttpResponse extends ReactiveHttpOutputMessage {
    /**
     * Set the HTTP status code to the given value (potentially non-standard and
     * not resolvable through the {@link HttpStatus} enum) as an integer.
     * @param value the status code value
     * @return {@code false} if the status code change wasn't processed because
     * the HTTP response is committed, {@code true} if successfully set.
     * @since 5.2.4
     */
    default boolean setRawStatusCode(@Nullable Integer value) {
        if (value == null) {
            return setStatusCode(null);
        }
        else {
            HttpStatus httpStatus = HttpStatus.resolve(value);
            if (httpStatus == null) {
                throw new IllegalStateException(
                        "Unresolvable HttpStatus for general ServerHttpResponse: " + value);
            }
            return setStatusCode(httpStatus);
        }
    }
}

Comment From: sbrannen

In Spring Framework 5.3.x, you can cast the response to AbstractServerHttpResponse and invoke setStatusCodeValue(Integer) to set a custom status code. See https://github.com/spring-projects/spring-framework/issues/24400#issuecomment-576294491.

In Spring Framework 6.x, you can invoke ServerHttpResponse#setRawStatusCode(Integer) to set a custom status code.

In light of that, I am closing this issue.