Class: Rack::TryStatic
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options) ⇒ TryStatic
constructor
A new instance of TryStatic.
Constructor Details
#initialize(app, options) ⇒ TryStatic
Returns a new instance of TryStatic.
22 23 24 25 26 |
# File 'lib/server.rb', line 22 def initialize(app, ) @app = app @try = ["", *[:try]] @static = ::Rack::Static.new(->(_) { [404, {}, []] }, ) end |
Instance Method Details
#call(env) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/server.rb', line 28 def call(env) orig_path = env["PATH_INFO"] found = nil @try.each do |path| resp = @static.call(env.merge!("PATH_INFO" => orig_path + path)) break if !(403..405).cover?(resp[0]) && found = resp end found || @app.call(env.merge!("PATH_INFO" => orig_path)) end |