Class: YesStatic
- Inherits:
-
Object
- Object
- YesStatic
- Defined in:
- lib/yes_static.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ YesStatic
constructor
A new instance of YesStatic.
Constructor Details
#initialize(app, options = {}) ⇒ YesStatic
Returns a new instance of YesStatic.
4 5 6 7 |
# File 'lib/yes_static.rb', line 4 def initialize(app, = {}) @app = app @root = [:root] || Dir.pwd end |
Instance Method Details
#call(env) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/yes_static.rb', line 9 def call(env) ext = File.extname(env[Rack::PATH_INFO]) return @app.call(env) if ext.empty? filepath = File.join(@root, env[Rack::PATH_INFO]) if File.exist?(filepath) last_modified = ::File.mtime(filepath).httpdate return [304, {}, []] if env["HTTP_IF_MODIFIED_SINCE"] == last_modified [200, { "content-type" => Rack::Mime.mime_type(ext), "last-modified" => last_modified }, File.open(filepath)] else [404, {}, []] end end |