1
votes

I am working on a Spring-Boot application. With each response I would like to return http Status-Line, Headers and Body. As per standards a Status-Line looks like: HTTP-Version SP Status-Code SP Reason-Phrase CRLF. For Example: Http/1.1 400 Bad Request

I am using ResponseEntity with VnDErrors but Status-Line is not forming as per standards. I am able to see only "Http/1.1 400". Here Reason-Phrase is missing.

I have tried with @ResponseBody with @ResponseStatus annotation but no luck to achieve desired result.

Here is piece of code which I am using:

@ExceptionHandler(HttpRequestMethodNotSupportedException)
    ResponseEntity<VndErrors> httpRequestMethodNotSupportedException(ex) {
        LOGGER.error(ex.message)
        ResponseEntity.status(BAD_REQUEST).contentType(VND_ERROR).body(new 
        VndErrors(BAD_REQUEST, exceptionMessage))
    }

Expected reponse which conatins Status-Line: "Http/1.1 400 Bad Request" Would like to know is this achievable? If yes, then how I can proceed to do same.

1

1 Answers

1
votes

This is the standard behavior of tomcat see tomcat-8.5-changelog.html

spring-boot-issue-6789

RFC 7230 states that clients should ignore reason phrases in HTTP/1.1 response messages. Since the reason phrase is optional, Tomcat no longer sends it. As a result the system property org.apache.coyote.USE_CUSTOM_STATUS_MSG_IN_HEADER is no longer used and has been removed. (markt)