From 81c9636d5510be5c4f1c59ce03f091d7cd0d726b Mon Sep 17 00:00:00 2001 From: Marek Goldmann Date: Tue, 5 Mar 2013 10:40:06 +0100 Subject: [PATCH] [TORQUE-1004] Document how to enable sendfile support in TorqueBox --- docs/manual/en-US/src/main/docbook/web.xml | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/docs/manual/en-US/src/main/docbook/web.xml b/docs/manual/en-US/src/main/docbook/web.xml index 8da72a973..fb21853b7 100644 --- a/docs/manual/en-US/src/main/docbook/web.xml +++ b/docs/manual/en-US/src/main/docbook/web.xml @@ -447,6 +447,90 @@ run app + +
+ Sendfile support + + + With TorqueBox it is possible to delegate the delivery of the response + content from a file to the application server itself, without + the need to read the file in the application. This is very useful for + static files. The X-Sendfile header is designed for this usage. + You can read more about Rack Sendfile. + Additionally the TorqueBox implementation allows to use byte-ranges to fetch only + part of the file by using the Range header. + + + + Sendfile support is available in TorqueBox for all Rack-based applications + (including Sinatra and Ruby on Rails frameworks). + + + + It is still possible to use a proxy in front of TorqueBox that handles the + X-Sendfile header instead of the application server. + TorqueBox will not handle the file if a special X-Sendfile-Type + header is set. + + + + By default the sendfile support is disabled in TorqueBox since it requires + native connectors in the JBoss AS web subsystem. + To enable the sendfile support in TorqueBox you need to modify the + $JBOSS_HOME/standalone/configuration/standalone.xml + file and change the native + attribute to true in the web subsystem, like this: + + + + <subsystem xmlns="urn:jboss:domain:web:1.4" default-virtual-server="default-host" native="true"> + ... +</subsystem> + + + + This will automatically make the sendfile support available. + + +
+ Examples + + + + Application sending content of <filename>thing.txt</filename> file + + app = lambda { |env| + [200, { 'Content-Type' => 'text/html', 'X-Sendfile' => 'thing.txt' }, "" ] +} +run app + + + + + + Receive bytes from 2 to 5 of the file content + curl -v -H "Range: bytes=2-5" http://localhost:8080/sendfile/ + + + + Receive content of file from beginning up to 10th byte + curl -v -H "Range: bytes=-10" http://localhost:8080/sendfile/ + + + + Receive content of file from 10th byte to the end + curl -v -H "Range: bytes=10-" http://localhost:8080/sendfile/ + + + + Multiple ranges + curl -v -H "Range: bytes=0-2/10-" http://localhost:8080/sendfile/ + + +
+ +
+