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.



170
171
172
# File 'lib/camping/server.rb', line 170

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/camping/server.rb', line 174

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



188
189
190
# File 'lib/camping/server.rb', line 188

def size(str)
  str.bytesize
end