class Rack::TrailingSlashes::Middleware

Constants

TRAILING_SLASHES_REGEX

Public Class Methods

new(app) click to toggle source
# File lib/rack/trailing_slashes/middleware.rb, line 5
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/rack/trailing_slashes/middleware.rb, line 9
def call(env)
  if env['REQUEST_METHOD'] == 'GET' && env['PATH_INFO'].match(TRAILING_SLASHES_REGEX)
    desired_path = $1
    [301, {'Location' => desired_path}, [redirect_message(desired_path)]]
  else
    @app.call(env)
  end
end

Private Instance Methods

redirect_message(location) click to toggle source
# File lib/rack/trailing_slashes/middleware.rb, line 20
def redirect_message(location)
  "Redirecting to <a href=\"#{location}\">#{location}</a>"
end