apachemod-filter

mod_filter: Why does a SUBSTITUTE not work for certain URLs?


I'm using mod-proxy in combination with mod-filter to make an internal server (nginx) accessible from outside of the network. My filter configuration is:

SetEnv filter-errordocs # necessary to process requests which don't have HTTP 200 OK
FilterDeclare ghe
FilterProvider gzinflate INFLATE resp=Content-Encoding $gzip
FilterProvider ghe SUBSTITUTE resp=Content-Type $text/
FilterProvider gzdeflate DEFLATE Content-Type $text/
FilterChain +gzinflate +ghe +gzdeflate
FilterTrace ghe 1

This works fine for HTML pages, for which curl -I http://internal/url gives something like:

HTTP/1.1 200 OK
Server: server.com
Date: Sat, 10 Aug 2013 14:55:25 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Status: 200 OK
Cache-Control: no-cache, no-store
X-Frame-Options: deny
Set-Cookie: logged_in=no; domain=.192.168.120.128; path=/; expires=Wed, 10-Aug-2033 14:55:25 GMT; HttpOnly
Set-Cookie: _fi_sess=xyz HttpOnly
X-Runtime: 19
ETag: "zyx"
Content-Length: 5928

However, it does not work when accessing e.g. css files for which curl -I http://internal/url.css gives something like:

HTTP/1.1 200 OK
Server: server.com
Date: Sat, 10 Aug 2013 14:55:31 GMT
Content-Type: text/css
Content-Length: 269455
Last-Modified: Fri, 09 Aug 2013 14:23:05 GMT
Connection: keep-alive
Accept-Ranges: bytes

The problem is somehow visible in Apache's error log (with debug LogLevel). For URLs to which the filter is applied, I see something like this (not sure if the EOS-part is the same request, though):

[Sat Aug 10 16:44:27 2013] [debug] mod_headers.c(756): headers: ap_headers_output_filter()
[Sat Aug 10 16:44:27 2013] [debug] mod_filter.c(117): [client 192.168.93.201] ghe
[Sat Aug 10 16:44:27 2013] [debug] mod_filter.c(122): [client 192.168.93.201] ghe: type: HEAP, length: 8096
[Sat Aug 10 16:44:27 2013] [debug] mod_filter.c(117): [client 192.168.93.201] ghe
[Sat Aug 10 16:44:27 2013] [debug] mod_filter.c(122): [client 192.168.93.201] ghe: type: HEAP, length: 8096
[Sat Aug 10 16:44:27 2013] [debug] mod_filter.c(117): [client 192.168.93.201] ghe
[Sat Aug 10 16:44:27 2013] [debug] mod_filter.c(122): [client 192.168.93.201] ghe: type: HEAP, length: 1097
[Sat Aug 10 16:44:27 2013] [debug] mod_filter.c(122): [client 192.168.93.201] ghe: type: EOS, length: 0
[Sat Aug 10 16:44:27 2013] [debug] mod_filter.c(117): [client 192.168.93.201] ghe
[Sat Aug 10 16:44:27 2013] [debug] mod_filter.c(122): [client 192.168.93.201] ghe: type: EOS, length: 0

For URLs for which the filter is not applied, I just see something like this:

[Sat Aug 10 16:44:27 2013] [debug] mod_headers.c(756): headers: ap_headers_output_filter()
[Sat Aug 10 16:44:27 2013] [debug] mod_filter.c(117): [client 192.168.93.201] ghe
[Sat Aug 10 16:44:27 2013] [debug] mod_filter.c(122): [client 192.168.93.201] ghe: type: EOS, length: 0

So, just EOS, but no HEAP, if that does mean anything.

How can this be fixed?


Solution

  • SUBSTITUTE filter may not work with Accept-Ranges: bytes. Using mod-header and adding following line to the Apache configuration file:

    Header set Accept-Ranges "none"
    

    will make the filter work.