Class: Camping::Server::XSendfile
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ XSendfile
constructor
A new instance of XSendfile.
- #size(str) ⇒ Object
Constructor Details
#initialize(app) ⇒ XSendfile
Returns a new instance of XSendfile.
240 241 242 |
# File 'lib/camping/server.rb', line 240 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/camping/server.rb', line 244 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
258 259 260 |
# File 'lib/camping/server.rb', line 258 def size(str) str.bytesize end |