Sha256: 67d8ca883b21e0ab5593b653cd37171f3334266f3b1feafb950bb9d2027e672a
Contents?: true
Size: 1.59 KB
Versions: 1
Compression:
Stored size: 1.59 KB
Contents
# frozen-string-literal: true # class Roda module RodaPlugins # The run_append_slash plugin makes +r.run+ use +/+ as the +PATH_INFO+ # when calling the rack application if +PATH_INFO+ would be empty. # Example: # # route do |r| # r.on "a" do # r.run App # end # end # # # without run_append_slash: # # GET /a => App gets "" as PATH_INFO # # GET /a/ => App gets "/" as PATH_INFO # # # with run_append_slash: # # GET /a => App gets "/" as PATH_INFO # # GET /a/ => App gets "/" as PATH_INFO module RunAppendSlash OPTS = {}.freeze RodaPlugins.deprecate_constant(self, :OPTS) # Set plugin specific options. Options: # :use_redirects :: Whether to issue 302 redirects when appending the # trailing slash. def self.configure(app, opts=RodaPlugins::OPTS) app.opts[:run_append_slash_redirect] = !!opts[:use_redirects] end module RequestMethods # Calls the given rack app. If the path matches the root of the app but # does not contain a trailing slash, a trailing slash is appended to the # path internally, or a redirect is issued when configured with # <tt>use_redirects: true</tt>. def run(app) if remaining_path.empty? if scope.opts[:run_append_slash_redirect] redirect("#{path}/") else @remaining_path += '/' end end super end end end register_plugin(:run_append_slash, RunAppendSlash) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
roda-2.29.0 | lib/roda/plugins/run_append_slash.rb |