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.
254 255 256 |
# File 'lib/camping/server.rb', line 254 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/camping/server.rb', line 258 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
272 273 274 |
# File 'lib/camping/server.rb', line 272 def size(str) str.bytesize end |