class Falcon::Redirection

def call(request)

def call(request)
	if host = lookup(request)
		if @endpoint.default_port?
			location = "#{@endpoint.scheme}://#{host.authority}#{request.path}"
		else
			location = "#{@endpoint.scheme}://#{host.authority}:#{@endpoint.port}#{request.path}"
		end
		
		return Protocol::HTTP::Response[301, [['location', location]], []]
	else
		super
	end
end

def initialize(app, hosts, endpoint)

def initialize(app, hosts, endpoint)
	super(app)
	
	@hosts = hosts
	@endpoint = endpoint
end

def lookup(request)

def lookup(request)
	# Trailing dot and port is ignored/normalized.
	if authority = request.authority.sub(/(\.)?(:\d+)?$/, '')
		return @hosts[authority]
	end
end