class Rackables::TrailingSlashRedirect

Request paths with a trailing slash are 301 redirected to the version without, e.g.:

GET /foo/   # => 301 redirects to /foo

Constants

HAS_TRAILING_SLASH

Public Class Methods

new(app) click to toggle source
# File lib/rackables/trailing_slash_redirect.rb, line 10
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/rackables/trailing_slash_redirect.rb, line 14
def call(env)
  req = Rack::Request.new(env)
  if req.path_info =~ HAS_TRAILING_SLASH
    req.path_info = "/#{$1}"
    [301, {"Location" => req.url}, []]
  else
    @app.call(env)
  end
end