Sha256: 6b24a82239d8f87d21c3097f1255eae856707479fb283c6691bcb8063d1990a1

Contents?: true

Size: 750 Bytes

Versions: 6

Compression:

Stored size: 750 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
        fallback_app = lambda { |env| [404, {}, []] }
        @static = ::Rack::Static.new(fallback_app, 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

6 entries across 6 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta10 lib/spontaneous/rack/static.rb
spontaneous-0.2.0.beta9 lib/spontaneous/rack/static.rb
spontaneous-0.2.0.beta8 lib/spontaneous/rack/static.rb
spontaneous-0.2.0.beta7 lib/spontaneous/rack/static.rb
spontaneous-0.2.0.beta6 lib/spontaneous/rack/static.rb
spontaneous-0.2.0.beta5 lib/spontaneous/rack/static.rb