Class: Camping::Server::XSendfile
Overview
A Rack middleware for reading X-Sendfile. Should only be used in development.
Constant Summary collapse
- HEADERS =
[ "X-Sendfile", "X-Accel-Redirect", "X-LIGHTTPD-send-file" ]
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ XSendfile
constructor
A new instance of XSendfile.
Constructor Details
#initialize(app) ⇒ XSendfile
Returns a new instance of XSendfile.
163 164 165 |
# File 'lib/camping/server.rb', line 163 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/camping/server.rb', line 167 def call(env) status, headers, body = @app.call(env) headers = Rack::Utils::HeaderHash.new(headers) if header = HEADERS.detect { |header| headers.include?(header) } path = headers[header] body = File.read(path) headers['Content-Length'] = body.length.to_s end [status, headers, body] end |