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 |
# File 'lib/route_downcaser/downcase_route_middleware.rb', line 12 def _call(env) request_uri = env['REQUEST_URI'] path_info = env['PATH_INFO'] # Don't touch anything, if uri/path is part of exclude_patterns if excluded?([request_uri, path_info]) return @app.call(env) end # Downcase request_uri and/or path_info if applicable request_uri = downcased_uri(request_uri) path_info = downcased_uri(path_info) # If redirect configured, then return redirect request, # if either request_uri or path_info has changed if RouteDowncaser.redirect && env['REQUEST_METHOD'] == "GET" if request_uri.present? && request_uri != env['REQUEST_URI'] return redirect_header(request_uri) end if path_info.present? && path_info != env['PATH_INFO'] return redirect_header(path_info) end end env['PATH_INFO'] = path_info.to_s if path_info env['REQUEST_URI'] = request_uri.to_s if request_uri # 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 |