<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>lighty's life: mod_proxy_core got X-Sendfile Support</title>
    <link>http://blog.lighttpd.net/articles/2006/07/22/mod_proxy_core-got-x-sendfile-support</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>mod_proxy_core got X-Sendfile Support</title>
      <description>&lt;p&gt;As promissed mod_proxy_core would combine the features from mod_proxy and mod_fastcgi.&lt;/p&gt;


	&lt;p&gt;mod_proxy gave the balancers, mod_fastcgi gave its fail-over handling and now support for X-Sendfile.&lt;/p&gt;
&lt;p&gt;The implementation for the feature is a bit different than it was done in mod_fastcgi.&lt;/p&gt;


	&lt;p&gt;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.&lt;/p&gt;


	&lt;p&gt;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.&lt;/p&gt;


mod_staticfile can do all the magic:
	&lt;ul&gt;
	&lt;li&gt;setting Last-Modified and ETag&lt;/li&gt;
		&lt;li&gt;handling &amp;#8216;304 Not Modified&amp;#8217;&lt;/li&gt;
		&lt;li&gt;handling Range requests&lt;/li&gt;
		&lt;li&gt;compression&lt;/li&gt;
	&lt;/ul&gt;


&lt;h3&gt;Setup&lt;/h3&gt;

	&lt;p&gt;The setup is as before:&lt;/p&gt;


&lt;pre&gt;
$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" 
}
&lt;/pre&gt;

	&lt;p&gt;On port 2000 I have a small &lt;kbd&gt;$ nc -l 2000&lt;/kbd&gt; running to simulate a super complex, high secure application. &lt;kbd&gt;$ wget --header='Accept-Encoding: gzip' http://127.0.0.1:1025/bugme/upload.html&lt;/kbd&gt; is my browser replacement:&lt;/p&gt;


&lt;pre&gt;
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
&lt;/pre&gt;

	&lt;p&gt;... and there we have the compressed &lt;kbd&gt;upload.html&lt;/kbd&gt;:&lt;/p&gt;


&lt;pre&gt;
$ 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
&lt;/pre&gt;

	&lt;p&gt;All you have to do in your application is setting the X-Sendfile header:&lt;/p&gt;


&lt;pre&gt;
&amp;lt;?php
  header("X-Sendfile: /path/to/upload.html");
?&amp;gt;
&lt;/pre&gt;

or in Rails:
&lt;pre&gt;
response.headers["X-Sendfile"] = "/path/to/upload.html" 
&lt;/pre&gt;</description>
      <pubDate>Sat, 22 Jul 2006 09:55:30 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:54e5c68a-0bd2-44c4-a436-d7a9328ffc0e</guid>
      <author>jan</author>
      <link>http://blog.lighttpd.net/articles/2006/07/22/mod_proxy_core-got-x-sendfile-support</link>
      <category>X</category>
      <category>Sendfile</category>
      <category>mod_proxy_core</category>
      <trackback:ping>http://blog.lighttpd.net/articles/trackback/1821</trackback:ping>
    </item>
  </channel>
</rss>
