Sha256: d9757b31d94f9ebcf666a0d3ad67f4f0f9b41b4183482ff3a992617ba487810b

Contents?: true

Size: 734 Bytes

Versions: 11

Compression:

Stored size: 734 Bytes

Contents

module Merb
  module Rack
    class PathPrefix < Merb::Rack::Middleware

      def initialize(app, path_prefix = nil)
        super(app)
        @path_prefix = /^#{Regexp.escape(path_prefix)}/
      end
      
      def deferred?(env)
        strip_path_prefix(env) 
        @app.deferred?(env)
      end
      
      def call(env)
        strip_path_prefix(env) 
        @app.call(env)
      end

      def strip_path_prefix(env)
        ['PATH_INFO', 'REQUEST_URI'].each do |path_key|
          if env[path_key] =~ @path_prefix
            env[path_key].sub!(@path_prefix, Merb::Const::EMPTY_STRING)
            env[path_key] = Merb::Const::SLASH if env[path_key].empty?
          end
        end
      end
      
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/merb-core-0.9.14/lib/merb-core/rack/middleware/path_prefix.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/merb-core-0.9.14/lib/merb-core/rack/middleware/path_prefix.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/merb-core-0.9.14/lib/merb-core/rack/middleware/path_prefix.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/merb-core-0.9.14/lib/merb-core/rack/middleware/path_prefix.rb
merb-core-1.1.0.rc1 spec10/public/webrat/test_app/gems/gems/merb-core-0.9.14/lib/merb-core/rack/middleware/path_prefix.rb
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/merb-core-0.9.14/lib/merb-core/rack/middleware/path_prefix.rb
merb-core-0.9.10 lib/merb-core/rack/middleware/path_prefix.rb
merb-core-0.9.11 lib/merb-core/rack/middleware/path_prefix.rb
merb-core-0.9.13 lib/merb-core/rack/middleware/path_prefix.rb
merb-core-0.9.12 lib/merb-core/rack/middleware/path_prefix.rb
merb-core-0.9.9 lib/merb-core/rack/middleware/path_prefix.rb