Apache dropping content-length response header from reverse proxy

Erik Thuning <[email protected]> Wed, 23 Apr 2025 11:41:29 +0200
Newsgroups gmane.comp.apache.user
Message-ID <[email protected]>
Hi!

I'd be grateful for any insight into what seems like it must be a simple 
issue, but I can't for the life of me find any answers in the 
documentation or on the wider internet.

I have an apache server running as reverse proxy for a tomcat 
application using mod_proxy_ajp. An external application pulling data 
from mine has a hard requirement to get a content-length header in the 
response and won't accept transfer-encoding=chunked. Tomcat is setting 
content-length as expected, but apache replaces it with 
transfer-encoding=chunked in its response.

How can I make apache stop switching these headers (and presumably stop 
streaming the response)? Preferrably only for a specified path 
(/divaexport), since the application is large and only a tiny portion 
has this content-length requirement.


My vhost configuration looks like this:

<VirtualHost *:80>
     ServerName redacted.example

     # Diva is an idiot and needs to be excluded from https
     RewriteEngine on
     RewriteRule ^(/divaexport) - [last]
     RewriteRule ^/(.*) https://daisy.dsv.su.se/$1 [redirect=301]

     ProxyPass / ajp://localhost:8009/

     LogFormat "%h %l %u %{%Y-%m-%d %H:%M:%S}t \"%r\" %>s %O 
\"%{Referer}i\" \"%{User-Agent}i\"" isotime
     CustomLog ${APACHE_LOG_DIR}/access.log isotime
</VirtualHost>


This is the response from tomcat when curl:ing it directly:

*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
 > GET /divaexport/fil?id=69212 HTTP/1.1
 > Host: localhost:8080
 > User-Agent: curl/7.74.0
 > Accept: */*
 >
* Mark bundle as not supporting multiuse
< HTTP/1.1 200
< Content-Disposition: inline; filename="afile.pdf"
< Content-Type: application/pdf;charset=utf-8
< Content-Language: en-GB
< Content-Length: 1820601
< Date: Wed, 23 Apr 2025 08:51:15 GMT


This is the response from apache:

*   Trying redacted:80...
* Connected to redacted.example (redacted) port 80 (#0)
 > GET /divaexport/fil?id=69212 HTTP/1.1
 > Host: redacted.example
 > User-Agent: curl/7.74.0
 > Accept: */*
 >
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 200
< Date: Wed, 23 Apr 2025 08:52:46 GMT
< Server: Apache/2.4
< Content-Disposition: inline; filename="afile.pdf"
< Content-Type: application/pdf;charset=utf-8
< Content-Language: en-GB
< Transfer-Encoding: chunked


/T