Bug 64775 - mod_jk is sending both Content-Length and Transfer-Encoding
Summary: mod_jk is sending both Content-Length and Transfer-Encoding
Status: NEW
Alias: None
Product: Tomcat Connectors
Classification: Unclassified
Component: mod_jk (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2020-09-28 19:33 UTC by Sam Horrocks
Modified: 2020-09-28 19:35 UTC (History)
1 user (show)


Note You need to log in before you can comment on or make changes to this bug.
Description Sam Horrocks 2020-09-28 19:33:39 UTC
Our application uses "Transfer Encoding: chunked" and it started to hang after upgrading mod_jk from 1.2.37 to 1.2.39. It's still broken in 1.2.48.  Looking at the headers it's because mod_jk is sending both of the following:

  Transfer-Encoding: chunked
  Content-Length: 0

Our app is assuming the content is zero-length and stops reading. In 1.2.37 both headers were present but Content-Length was empty instead of zero, which our app had been ignoring.

  Transfer-Encoding: chunked

According to the HTTP spec the web server should never send both of these headers in the same response.  It looks like the patch in r1549202 started sending a numeric Content-Length instead of an empty one which is when it broke for us.

The following patch checks if the Content-Length is empty and if so doesn't sent the header at all.  With this patch I only see the Transfer-Encoding header and no Content-Length.

--- tomcat-connectors-1.2.48-src.orig/native/apache-2.0/mod_jk.c        2020-02-20 11:43:15.000000000 -0500
+++ tomcat-connectors-1.2.48-src/native/apache-2.0/mod_jk.c     2020-09-18 10:56:14.564911842 -0400
@@ -395,7 +395,9 @@
             apr_table_set(r->headers_out, header_names[h], header_values[h]);
         else if (!strcasecmp(header_names[h], "Content-Length")) {
-            ap_set_content_length(r, apr_atoi64(header_values[h]));
+           if (strlen(header_values[h]) > 0) {
+               ap_set_content_length(r, apr_atoi64(header_values[h]));
+           }
         else if (!strcasecmp(header_names[h], "Transfer-Encoding")) {
             apr_table_set(r->headers_out, header_names[h], header_values[h]);