Jersey response's reason phrase is inconsistent in tomcat 7 and 8.5

user7294900 :

I'm using Tomcat 8.5 in one server and Tomcat 7 in different server and I have the following jersey resource:

@Path("main")
public class MyResource {


@POST
@Path("path")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public PojoResponse sendMailTemplate(PojoRequest paramsMap) throws Exception {
    return service.execute(paramsMap);
}

Which is register to MyApplication (extends ResourceConfig) with @ApplicationPath("root")

When submitting request using JMeter/Postman (to /root/main/path) I'm getting inconsistent HTTP's Reason Phrase

The client is not required to examine or display the Reason- Phrase.

Which isn't mandatory for protocol

The reason phrases listed here are only recommendations -- they MAY be replaced by local equivalents without affecting the protocol.

I see a "valid" response of 200 OK from Tomcat 7 server:

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/json
Content-Length: 32

and an "invalid" response of 200 200 from Tomcat 7 server (same request) :

HTTP/1.1 200 200
Server: Apache
Content-Type: application/json
Content-Length: 32
X-Content-Type-Options: nosniff
X-XSS-Protection: 1
Connection: close
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload

When I check Response I don't find any reference to updating reason phrase, So should this inconsistency be ignored or can it be fixed?

EDIT

My application also register JacksonFeature:

register(JacksonFeature.class);

EDIT 2

Actually I found that I have extra jar in second environment:

 jersey-entity-filtering-2.19

Common jars:

jersey-client-2.19.jar
jersey-common-2.19.jar
jersey-container-servlet-2.19.jar
jersey-container-servlet-core-2.19.jar
jersey-guava-2.19.jar
jersey-media-jaxb-2.19.jar
jersey-media-json-jackson-2.6.jar
jersey-server-2.19.jar
jersey-spring3-2.6.jar

EDIT 3

I found a bug in Tomcat 8.5 which saying reason phrase was removed

Christopher Schultz : I was surprised to see that Tomcat actively strips-out the reason phrase. I had initially thought this was simply Tomcat removing reason-phrases from every response generated by Tomcat (e.g. everything coming from the DefaultServlet, various internal errors, etc.), but it's actively stripping reason phrases explicitly-set by applications.

Michael Osipov: No, this does not send any reason phrase. Only the HTML error page. I know, because I have rewritten the ErrorReportValve the last time.

EDIT 4

I found relevant question but I didn't fully understand it

Tomcat 8.5 removed the "HTTP status reason phrase" from the response, so you'll get HTTP 200 instead of HTTP 200 OK in the response. It's possible that your observations are from software that duplicates the status code into the status reason phrase for display.

How are you observing the status code? You may find that if you do a protocol trace, you'll see that there is only a single status code being sent by Tomcat / httpd. Are you sure the "double status code" isn't actually a (normal) status code and a reason phrase that happens to be the same text as the status code?

Konstantin Kolinko :

I just answered a similar question (52821653) two days ago.

In short: the current version of HTTP protocol (HTTP/2) has removed support for the reason phrase.

This feature is gone. Do not rely on it.

UPDATE:

Looking at

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1

and

HTTP/1.1 200 200
Server: Apache

The HTTP connector of current versions of Tomcat 8.5 by default will respond with HTTP/1.1 200 (with no reason phrase). See org.apache.coyote.http11.Http11OutputBuffer.

The AJP connector of current versions of Tomcat 8.5 by default will respond with HTTP/1.1 200 200 (using the status code as the reason phrase), because of limitations of some HTTP servers. See org.apache.coyote.ajp.AjpProcessor.

Both responses are valid ones.

Generating the "OK" string can be enabled in Tomcat 8.5 by setting sendReasonPhrase="true" on a Connector. This option is deprecated.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=115201&siteId=1
8.5