Class: Falcon::Redirection
- Inherits:
-
Async::HTTP::Middleware
- Object
- Async::HTTP::Middleware
- Falcon::Redirection
- Defined in:
- lib/falcon/redirection.rb
Instance Method Summary collapse
- #call(request) ⇒ Object
-
#initialize(app, hosts, endpoint) ⇒ Redirection
constructor
A new instance of Redirection.
- #lookup(request) ⇒ Object
Constructor Details
#initialize(app, hosts, endpoint) ⇒ Redirection
Returns a new instance of Redirection.
34 35 36 37 38 39 |
# File 'lib/falcon/redirection.rb', line 34 def initialize(app, hosts, endpoint) super(app) @hosts = hosts @endpoint = endpoint end |
Instance Method Details
#call(request) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/falcon/redirection.rb', line 48 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 Async::HTTP::Response[301, [['location', location]], []] else super end end |
#lookup(request) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/falcon/redirection.rb', line 41 def lookup(request) # Trailing dot and port is ignored/normalized. if = request..sub(/(\.)?(:\d+)?$/, '') return @hosts[] end end |