No commit activity in last 3 years
No release in over 3 years
X-SendFile helpers for Sinatra
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0.3.0

Runtime

>= 0.9.1
>= 0.9.1
 Project Readme

Sinatra Extension: XSendFile

sinatra-xsendfile extension provides x_send_file helper method for sending files faster

NOTE: sinatra-xsendfile is no longer supported. Consider using Rack::Sendfile instead.

##XSendFile

##Installation

If you use bundler, simply specify sinatra-xsendfile as a dependency in a Gemfile in your project's root:

gem 'sinatra-xsendfile'

and run bundle install.

Otherwise install the gem as usual:

[sudo] gem install sinatra-xsendfile

##Example

require 'rubygems'
require 'sinatra'
require 'sinatra/xsendfile'

configure :production do
  Sinatra::Xsendfile.replace_send_file! # replace Sinatra's send_file with x_send_file
  set :xsf_header, 'X-Accel-Redirect' # set x_send_file header (default: X-SendFile)
end

get '/' do
  x_send_file(__FILE__)
end

get '/lighttpd' do
  x_send_file(__FILE__, header: 'X-LIGHTTPD-send-file') # custom header
end

get '/sendfile' do
  send_file(__FILE__) # will work as x_send_file in production (see configure block)
end

Note that if your application subclasses Sinatra::Base (modular app), you have to register the extension in your subclass:

helpers Sinatra::Xsendfile