Class: Rack::Slashless

Inherits:
Object
  • Object
show all
Defined in:
lib/rack_slashless.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Slashless

Returns a new instance of Slashless.



4
5
6
# File 'lib/rack_slashless.rb', line 4

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/rack_slashless.rb', line 8

def call(env)
  request = Rack::Request.new(env)
  if request.get? && request.path_info.match(/.+\/$/)
    destination = request.url.gsub(/\/(\?.*)?$/,'\1')
    [301, {'Location' => destination, 'Content-Type' => 'text/html'}, ["Redirecting to #{destination}"]]
  else
    @app.call(env)
  end
end