lighty's life

lighty developer blog

Mod_proxy_core Got X-Sendfile Support

As promissed mod_proxy_core would combine the features from mod_proxy and mod_fastcgi. mod_proxy gave the balancers, mod_fastcgi gave its fail-over handling and now support for X-Sendfile. The implementation for the feature is a bit different than it was done in mod_fastcgi. The old implementation only replaced the content-body with the static-file and sent it out. The new implementation does it slightly different and gains a whole set of benifits. When the X-Sendfile header is detected (and is allowed in the config) the content-body is ignored and a internal redirect is done. mod_proxy_core takes itself out of the loop and mod_staticfile takes over the request. mod_staticfile can do all the magic: * setting Last-Modified and ETag * handling '304 Not Modified' * handling Range requests * compression

Setup

The setup is as before:
$HTTP["url"] =~ "^/bugme(/|$)" {
    proxy-core.balancer = "round-robin"
    proxy-core.protocol = "http"
    proxy-core.backends = ( "127.0.0.1:2000" )
    proxy-core.allow-x-sendfile = "enable"
}
On port 2000 I have a small $ nc -l 2000 running to simulate a super complex, high secure application. $ wget --header='Accept-Encoding: gzip' http://127.0.0.1:1025/bugme/upload.html is my browser replacement:
GET /bugme/upload.html HTTP/1.0
X-Forwarded-For: 127.0.0.1
X-Host: 127.0.0.1:1025
X-Forwarded-Proto: http
User-Agent: Wget/1.10.2 (Red Hat modified)
Accept: */*
Host: 127.0.0.1:1025
Accept-Encoding: gzip
FOO: foo

HTTP/1.0 200 OK
X-Sendfile: /path/to/upload.html
... and there we have the compressed upload.html:
$ ls -l upload.html
-rw-rw-r--  1 jan jan 661 Sep 26  2005 upload.html
$ ls -l /path/to/upload.html
-rw-rw-r--  1 jan jan 1193 Sep 26  2005 /path/to/upload.html
All you have to do in your application is setting the X-Sendfile header:

or in Rails:
response.headers["X-Sendfile"] = "/path/to/upload.html"