Sha256: 1e15beeab461cac4a2d735916e6bbbe48952918213711fc890fc0985885b15c5

Contents?: true

Size: 735 Bytes

Versions: 9

Compression:

Stored size: 735 Bytes

Contents

module Spontaneous
  module Rack
    class Static
      ALLOWED_METHODS = %w(GET HEAD).freeze

      def initialize(app, options)
        @app = app
        @try = ['', *options.delete(:try)].compact
        @static = ::Rack::Static.new(
          lambda { |env| [404, {}, []] },
          options)
      end

      def call(env)
        return @app.call(env) unless ALLOWED_METHODS.include?(env[S::REQUEST_METHOD])
        orig_path = env['PATH_INFO']
        found = nil
        @try.each do |path|
          resp = @static.call(env.merge!({'PATH_INFO' => orig_path + path}))
          break if 404 != resp[0] && found = resp
        end
        found or @app.call(env.merge!('PATH_INFO' => orig_path))
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta4 lib/spontaneous/rack/static.rb
spontaneous-0.2.0.beta3 lib/spontaneous/rack/static.rb
spontaneous-0.2.0.beta2 lib/spontaneous/rack/static.rb
spontaneous-0.2.0.beta1 lib/spontaneous/rack/static.rb
spontaneous-0.2.0.alpha7 lib/spontaneous/rack/static.rb
spontaneous-0.2.0.alpha6 lib/spontaneous/rack/static.rb
spontaneous-0.2.0.alpha5 lib/spontaneous/rack/static.rb
spontaneous-0.2.0.alpha4 lib/spontaneous/rack/static.rb
spontaneous-0.2.0.alpha3 lib/spontaneous/rack/static.rb