Class: Camping::Server::XSendfile

Inherits:
Object
  • Object
show all
Defined in:
lib/camping/server.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ XSendfile

Returns a new instance of XSendfile.



258
259
260
# File 'lib/camping/server.rb', line 258

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/camping/server.rb', line 262

def call(env)
  status, headers, body = @app.call(env)

  if key = headers.keys.grep(/X-Sendfile/i).first
    filename = headers[key]
    content = open(filename,'rb') { | io | io.read}
    headers['Content-Length'] = size(content).to_s
    body = [content]
  end

  return status, headers, body
end

#size(str) ⇒ Object



276
277
278
# File 'lib/camping/server.rb', line 276

def size(str)
  str.bytesize
end