Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicated status code in response

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.

like image 505
priethor Avatar asked Aug 18 '26 05:08

priethor


2 Answers

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. ;-)

like image 181
r0bb3n Avatar answered Aug 21 '26 06:08

r0bb3n


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.

like image 34
Christopher Schultz Avatar answered Aug 21 '26 07:08

Christopher Schultz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!