FalconSourceFalconEnvironmentRedirect

module Redirect

Provides an environment for redirecting insecure web traffic to a secure endpoint.

Definitions

def redirect_url

The URL template to redirect to.

Signature

returns String

The redirect URL template.

Implementation

def redirect_url
	"https://[::]:443"
end

def redirect_endpoint

Parse the redirect URL into an endpoint.

Signature

returns Async::HTTP::Endpoint

The redirect endpoint.

Implementation

def redirect_endpoint
	Async::HTTP::Endpoint.parse(redirect_url)
end

def environments

The services we will redirect to.

Signature

returns Array(Async::Service::Environment)

Implementation

def environments
	[]
end

def hosts

Build a hash of host authorities to their evaluators for redirect matching.

Signature

returns Hash(String, Async::Service::Environment::Evaluator)

Map of host authorities to evaluators.

Implementation

def hosts
	hosts = {}
	
	environments.each do |environment|
		evaluator = environment.evaluator
		
		if environment.implements?(Falcon::Environment::Application)
			Console.info(self) {"Redirecting #{self.url} to #{evaluator.authority}"}
			hosts[evaluator.authority] = evaluator
		end
	end
	
	return hosts
end

def middleware

Load the class Falcon::Middleware::Redirect application with the specified hosts.

Implementation

def middleware
	Middleware::Redirect.new(Middleware::NotFound, hosts, redirect_endpoint)
end