Using X-Sendfile in Rails with lighttpd

As a followup to my post on using x-sendfile, I sent some email to Jan, owner of lighttpd. He clued me into the mod_setenv module that allows me to write this in my lighttpd.conf:

setenv.add-environment = (
  "ENABLE_X_SENDFILE" => "true"
)

as well as the allow-x-send-file property for FastCGI and soon to be proxy-core configuration.

Now my Rails source code can look like this:

  if request.env["ENABLE_X_SENDFILE"] == "true"
    response.headers["X-Sendfile"] = filename_to_send
  else
    response.body = read_file(filename_to_send)
  end

The configuration to enable x-sendfile is duplicated, but at least it’s in a single .conf file.

This entry was posted on Thu, 02 Nov 2006 09:28:02 GMT . You can follow any any response to this entry through the Atom feed. You can leave a comment .
Tags


Comments

Leave a response

Leave a comment