Class: Falcon::Controller::Proxy

Inherits:
Serve
  • Object
show all
Defined in:
lib/falcon/controller/proxy.rb

Constant Summary collapse

DEFAULT_SESSION_ID =
"falcon"

Instance Method Summary collapse

Methods inherited from Serve

#create_container, #setup, #stop

Constructor Details

#initialize(command, session_id: DEFAULT_SESSION_ID, **options) ⇒ Proxy

Returns a new instance of Proxy.



36
37
38
39
40
41
# File 'lib/falcon/controller/proxy.rb', line 36

def initialize(command, session_id: DEFAULT_SESSION_ID, **options)
	super(command, **options)
	
	@session_id = session_id
	@hosts = {}
end

Instance Method Details

#endpointObject



84
85
86
87
88
89
# File 'lib/falcon/controller/proxy.rb', line 84

def endpoint
	@command.endpoint.with(
		ssl_context: self.ssl_context,
		reuse_address: true,
	)
end

#host_context(socket, hostname) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/falcon/controller/proxy.rb', line 51

def host_context(socket, hostname)
	if host = @hosts[hostname]
		Async.logger.debug(self) {"Resolving #{hostname} -> #{host}"}
		
		socket.hostname = hostname
		
		return host.ssl_context
	else
		Async.logger.warn(self) {"Unable to resolve #{hostname}!"}
		
		return nil
	end
end

#load_appObject



43
44
45
# File 'lib/falcon/controller/proxy.rb', line 43

def load_app
	return Middleware::Proxy.new(Middleware::BadRequest, @hosts)
end

#nameObject



47
48
49
# File 'lib/falcon/controller/proxy.rb', line 47

def name
	"Falcon Proxy Server"
end

#ssl_contextObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/falcon/controller/proxy.rb', line 65

def ssl_context
	@server_context ||= OpenSSL::SSL::SSLContext.new.tap do |context|
		context.servername_cb = Proc.new do |socket, hostname|
			self.host_context(socket, hostname)
		end
		
		context.session_id_context = @session_id
		
		context.ssl_version = :TLSv1_2_server
		
		context.set_params(
			ciphers: TLS::SERVER_CIPHERS,
			verify_mode: OpenSSL::SSL::VERIFY_NONE,
		)
		
		context.setup
	end
end

#startObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/falcon/controller/proxy.rb', line 91

def start
	configuration = @command.configuration
	
	services = Services.new(configuration)
	
	@hosts = {}
	
	services.each do |service|
		if service.is_a?(Service::Proxy)
			Async.logger.info(self) {"Proxying #{service.authority} to #{service.endpoint}"}
			@hosts[service.authority] = service
		end
	end
	
	super
end