class Rack::Speling

Constants

DESCRIPTION
SUMMARY
VERSION

Attributes

app[R]
env[R]
lookup[R]
response[R]

Public Class Methods

new(app, options = {}) click to toggle source

remember the application as we need to call before or after this an lookup-object may be supplied for further 404-handling

# File lib/rack/speling.rb, line 9
def initialize(app, options = {})
  @app = app
  @lookup = options[:lookup] || {}
end

Public Instance Methods

call(env) click to toggle source

downcase PATH_INFO and REQUEST_URI furthermore, try to lookup 404s to react with a redirect

# File lib/rack/speling.rb, line 16
def call(env)
  @env = env

  downcase_path

  @response = app.call(env)

  if response[0] == 404 && path_lookup
    correct_response
  else
    response
  end
end

Private Instance Methods

correct_response() click to toggle source
# File lib/rack/speling.rb, line 32
def correct_response
  headers = response[1].merge({
    'Location' => new_location
  })

  [302, headers, ["Moved: #{headers['Location']}"]]
end
downcase_path() click to toggle source
# File lib/rack/speling.rb, line 52
def downcase_path
  env['PATH_INFO']   = env['PATH_INFO'].downcase
  env['REQUEST_URI'] = env['REQUEST_URI'].downcase
end
new_location() click to toggle source
# File lib/rack/speling.rb, line 40
def new_location
  path_lookup.start_with?('http:') ? path_lookup : "http://#{env['HTTP_HOST']}#{path_lookup}"
end
path() click to toggle source
# File lib/rack/speling.rb, line 48
def path
  env['PATH_INFO']
end
path_lookup() click to toggle source
# File lib/rack/speling.rb, line 44
def path_lookup
  @path_lookup ||= lookup[path]
end