Class: Falcon::Middleware::Redirect
- Inherits:
-
Protocol::HTTP::Middleware
- Object
- Protocol::HTTP::Middleware
- Falcon::Middleware::Redirect
- Defined in:
- lib/falcon/middleware/redirect.rb
Instance Method Summary collapse
- #call(request) ⇒ Object
-
#initialize(app, hosts, endpoint) ⇒ Redirect
constructor
A new instance of Redirect.
- #lookup(request) ⇒ Object
Constructor Details
#initialize(app, hosts, endpoint) ⇒ Redirect
Returns a new instance of Redirect.
37 38 39 40 41 42 |
# File 'lib/falcon/middleware/redirect.rb', line 37 def initialize(app, hosts, endpoint) super(app) @hosts = hosts @endpoint = endpoint end |
Instance Method Details
#call(request) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/falcon/middleware/redirect.rb', line 51 def call(request) if host = lookup(request) if @endpoint.default_port? location = "#{@endpoint.scheme}://#{host.}#{request.path}" else location = "#{@endpoint.scheme}://#{host.}:#{@endpoint.port}#{request.path}" end return Protocol::HTTP::Response[301, [['location', location]], []] else super end end |
#lookup(request) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/falcon/middleware/redirect.rb', line 44 def lookup(request) # Trailing dot and port is ignored/normalized. if = request.&.sub(/(\.)?(:\d+)?$/, '') return @hosts[] end end |