Duplicated status code in response

老子叫甜甜 提交于 2020-01-03 04:29:08

问题


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.


回答1:


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.




回答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.




回答3:


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



来源:https://stackoverflow.com/questions/44152778/duplicated-status-code-in-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!