Sha256: e1710028c1c82e4112ae5b7480d7add59ee23c9a8979336c701e87e0b4d63652

Contents?: true

Size: 1.41 KB

Versions: 30

Compression:

Stored size: 1.41 KB

Contents

# frozen-string-literal: true

#
class Roda
  module RodaPlugins
    # The run_require_slash plugin makes +r.run+ a no-op if the remaining
    # path is not empty and does not start with +/+. The Rack SPEC requires that
    # +PATH_INFO+ start with a slash if not empty, so this plugin prevents
    # dispatching to the application with an environment that would violate the
    # Rack SPEC.
    #
    # You are unlikely to want to use this plugin unless are consuming partial
    # segments of the request path, or using the match_affix plugin to change
    # how routing is done:
    #
    #   plugin :match_affix, "", /(\/|\z)/
    #   route do |r|
    #     r.on "/a" do
    #       r.on "b" do
    #         r.run App
    #       end
    #     end
    #   end
    #
    #   # with run_require_slash: 
    #   # GET /a/b/e => App not dispatched to
    #   # GET /a/b => App gets "" as PATH_INFO
    #
    #   # with run_require_slash: 
    #   # GET /a/b/e => App gets "e" as PATH_INFO, violating rack SPEC
    #   # GET /a/b => App gets "" as PATH_INFO
    module RunRequireSlash
      module RequestMethods
        # Calls the given rack app only if the remaining patch is empty or
        # starts with a slash.
        def run(*)
          if @remaining_path.empty? || @remaining_path.start_with?('/')
            super
          end
        end
      end
    end

    register_plugin(:run_require_slash, RunRequireSlash)
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
roda-3.86.0 lib/roda/plugins/run_require_slash.rb
roda-3.85.0 lib/roda/plugins/run_require_slash.rb
roda-3.84.0 lib/roda/plugins/run_require_slash.rb
roda-3.83.0 lib/roda/plugins/run_require_slash.rb
roda-3.82.0 lib/roda/plugins/run_require_slash.rb
roda-3.81.0 lib/roda/plugins/run_require_slash.rb
roda-3.79.0 lib/roda/plugins/run_require_slash.rb
roda-3.78.0 lib/roda/plugins/run_require_slash.rb
roda-3.77.0 lib/roda/plugins/run_require_slash.rb
roda-3.76.0 lib/roda/plugins/run_require_slash.rb
roda-3.75.0 lib/roda/plugins/run_require_slash.rb
roda-3.74.0 lib/roda/plugins/run_require_slash.rb
roda-3.73.0 lib/roda/plugins/run_require_slash.rb
roda-3.72.0 lib/roda/plugins/run_require_slash.rb
roda-3.71.0 lib/roda/plugins/run_require_slash.rb
roda-3.70.0 lib/roda/plugins/run_require_slash.rb
roda-3.69.0 lib/roda/plugins/run_require_slash.rb
roda-3.68.0 lib/roda/plugins/run_require_slash.rb
roda-3.67.0 lib/roda/plugins/run_require_slash.rb
roda-3.66.0 lib/roda/plugins/run_require_slash.rb