Class: RouteDowncaser::DowncaseRouteMiddleware
- Inherits:
-
Object
- Object
- RouteDowncaser::DowncaseRouteMiddleware
- Defined in:
- lib/route_downcaser/downcase_route_middleware.rb
Instance Method Summary collapse
- #_call(env) ⇒ Object
- #call(env) ⇒ Object
-
#initialize(app) ⇒ DowncaseRouteMiddleware
constructor
A new instance of DowncaseRouteMiddleware.
Constructor Details
#initialize(app) ⇒ DowncaseRouteMiddleware
Returns a new instance of DowncaseRouteMiddleware.
4 5 6 |
# File 'lib/route_downcaser/downcase_route_middleware.rb', line 4 def initialize(app) @app = app end |
Instance Method Details
#_call(env) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/route_downcaser/downcase_route_middleware.rb', line 12 def _call(env) old_env = { 'REQUEST_URI' => env['REQUEST_URI'], 'PATH_INFO' => env['PATH_INFO'] } # Don't touch anything, if uri/path is part of exclude_patterns if exclude_patterns_match?(env['REQUEST_URI']) or exclude_patterns_match?(env['PATH_INFO']) return @app.call(env) end # Downcase request_uri and/or path_info if applicable if env['REQUEST_URI'].present? env['REQUEST_URI'] = downcased_uri(env['REQUEST_URI']) end if env['PATH_INFO'].present? env['PATH_INFO'] = downcased_uri(env['PATH_INFO']) end # If redirect configured, then return redirect request, # if either request_uri or path_info has changed if RouteDowncaser.redirect && env['REQUEST_METHOD'] == "GET" if env["REQUEST_URI"].present? and old_env["REQUEST_URI"] != env["REQUEST_URI"] return redirect_header(env["REQUEST_URI"]) end if env["PATH_INFO"].present? and old_env["PATH_INFO"] != env["PATH_INFO"] return redirect_header(env["PATH_INFO"]) end end # Default just move to next chain in Rack callstack # calling with downcased uri if needed @app.call(env) end |
#call(env) ⇒ Object
8 9 10 |
# File 'lib/route_downcaser/downcase_route_middleware.rb', line 8 def call(env) dup._call(env) end |