2

I usually deploy Java webapps in Tomcat servers and access them through an Apache proxy, using proxy_ajp. The thing is, in my latests setups (which are all basically the same) I see that the status code I get in all my requests is duplicated (i.e., "Status Code:200 200"). I get this in every browser, in Postman, and for any status code I might get, and everything seems to work fine, but I'm concerned my setup might not be optimal.

Although I can't find a solution, I have narrowed the issue down to the ajp_proxy, as if I change

ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/

with:

ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/

I get just a single status code for my requets, as expected.

I have searched for this issue and I haven't found anything even marginally related to it, so any information would be very much appreciated.

Server information:

  • Apache version: Apache/2.4.18 (Ubuntu)
  • Tomcat version: apache-tomcat-8.5.13

Thanks in advance.

priethor
  • 93
  • 2
  • 7

3 Answers3

4

This is not an issue of any client software, it's a result of a workaround contained in the Tomcat for a specific AJP issue from 2008: Tomcat Issue Tracker #45026

Here you can see the corresponding code snippet of org.apache.coyote.ajp.AjpProcessor (Github):

if (sendReasonPhrase) {
    /* ... */
    if (message == null) {
        // mod_jk + httpd 2.x fails with a null status message - bug 45026
        message = Integer.toString(response.getStatus());
    }
    tmpMB.setString(message);
} else {
    // Reason phrase is optional but mod_jk + httpd 2.x fails with a null
    // reason phrase - bug 45026
    tmpMB.setString(Integer.toString(response.getStatus()));
}

Finally this means, that every AJP-based response will deliver always a HTTP status reason phrase - at least with the status number as content.

This explains exactly the observed behavior of your two ProxyPass scenarios.

I would suggest to enable sending the reason phrase via sendReasonPhrase attribute within the AJP Connector as long as you stay at Tomcat 8.5.

This attributes also exists for the HTTP Connector. ;-)

r0bb3n
  • 61
  • 3
2

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.

Christopher Schultz
  • 20,221
  • 9
  • 60
  • 77
  • 1
    I'm observing the status code through different tools: Chrome's network console, Firebug, Postman and even [Hurl](https://www.hurl.it), and in all of them I do get a double status code. On a side note, I have some Apache rewrite rules (typical if http go to https and similar ones) and they do work fine, just one response code and reason phase, but once you actually get the page from Tomcat through proxy_ajp, I get double status code and, as you said, without response phrase, which is totally fine. – priethor May 25 '17 at 06:42
  • 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? – Christopher Schultz May 25 '17 at 13:58
  • 1
    DOH! I just performed a request to my site with my own code in order to debug it and see the actual response and you are absolutely right, I'm just getting the status code both in the status field and as the status text. Many thanks. – priethor May 26 '17 at 07:57
2

Actually, as Christopher Schultz pointed out, I'm getting the status code both as the status code and the status reason text.

Getting "double" status code is just a visual mislead one can encounter when using API testing tools, which usually pretty print together, as a single piece of information, both the status code and the status reason text.

priethor
  • 93
  • 2
  • 7
  • I just open a bounty and I'm using JMeter/Postman to send requests https://stackoverflow.com/questions/52696556/jersey-responses-reason-phrase-is-inconsistent-in-different-servers/52868017#comment92650081_52868017 – Ori Marko Oct 18 '18 at 08:20