Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add reason phrase back in spring-boot 1.4.x

As noted here and here, the latest version of Spring Boot (1.4.x) does not return the reason phrase due to the new version of Tomcat.

Unfortunately I am constrained by some legacy code that I cannot influence, and I need to add the "OK" reason phrase back to my responses. Any idea how to do this? If it was a header, it would be easy to modify with an HttpServletResponseWrapper. But with the status line, I cannot even find the code where the status line is written.

I really don't want to have to (indefinitely) downgrade to old tech. Hopefully someone knows a way to add this back in.

like image 813
Ken DeLong Avatar asked Oct 14 '16 04:10

Ken DeLong


2 Answers

Add the following attribute to your Connection in conf\server.xml:

sendReasonPhrase="true"

In Tomcat 8.5.x the reason phrase was no longer sent by default.

like image 172
WW. Avatar answered Sep 21 '22 15:09

WW.


To add reason phrase back to spring-boot's embedded tomcat simply declare the following bean in your app config:

@Bean
    public EmbeddedServletContainerFactory servletContainer() {
        TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
        factory.addConnectorCustomizers(
                (TomcatConnectorCustomizer) connector -> connector.setProperty("sendReasonPhrase", "true"));
        return factory;
    }

Works since Spring-Boot 1.5.3.RELEASE and untill embedded tomcat will be updated to 9.x version https://bz.apache.org/bugzilla/show_bug.cgi?id=61160

like image 32
MeetJoeBlack Avatar answered Sep 19 '22 15:09

MeetJoeBlack