class Rack::TryStatic

Public Class Methods

new(app, options) click to toggle source
# File lib/kamishibai/patches.rb, line 40
def initialize(app, options)
  @app = app
  @try = ['', *options[:try]]
  @static = ::Rack::Static.new(
    lambda { |_| [404, {}, []] },
    options)
end

Public Instance Methods

call(env) click to toggle source
# File lib/kamishibai/patches.rb, line 48
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).include?(resp[0]) && found = resp
  end
  found or @app.call(env.merge!('PATH_INFO' => orig_path))
end