torquebox/torquebox — pull request #113 by parbst (2013-01-04 21:58:05+00:00)
Title: Enabling native sendfile for rack

I've added a servlet filter before the RackFilter which enables functionality equivalent to mod_xsendfile available in apache httpd. It does this by using the JBoss native web connectors which are bundled into JBoss 7.

If the native connectors are enabled, the filter activates and sends the X-Sendfile-Type header to the rack filter. If the, for instance, rails process is set up to use X-Sendfile, it will leave the actual sending of the file to a later process, by setting the X-Sendfile header. This is intercepted in the filter, which sets up the file transfer with the native connecors.

I've implemented support for the HTTP Range header, which specifies which parts of the file to send. This is functionality in the native connector and necessary for, for instance, media streaming. I think the filter is the correct layer to put that check. In that manner, the filter also set other headers it can answer for.

It should be possible to reuse the filter, since it is agnostic of the rack process. The only demand is that it sits in the filter chain before the ResponseFacade is wrapped in another HttpServletResponseWrapper.