diff --git a/falcon.gemspec b/falcon.gemspec index 03347241..dd631057 100644 --- a/falcon.gemspec +++ b/falcon.gemspec @@ -30,7 +30,7 @@ Gem::Specification.new do |spec| spec.add_dependency "async-http", "~> 0.57" spec.add_dependency "async-http-cache", "~> 0.4.0" spec.add_dependency "async-io", "~> 1.22" - spec.add_dependency "async-service", "~> 0.9.0" + spec.add_dependency "async-service", "~> 0.10.0" spec.add_dependency "bundler" spec.add_dependency "localhost", "~> 1.1" spec.add_dependency "openssl", "~> 3.0" diff --git a/lib/falcon/command/proxy.rb b/lib/falcon/command/proxy.rb index 93e15f4c..f7f96e75 100644 --- a/lib/falcon/command/proxy.rb +++ b/lib/falcon/command/proxy.rb @@ -42,39 +42,10 @@ def environment(**options) ) end - def host_map(environments) - hosts = {} - - environments.each do |environment| - next unless environment.implements?(Falcon::Environment::Application) - evaluator = environment.evaluator - - if RUBY_VERSION < '3.1' - # Prepare the ssl_context: - evaluator.ssl_context - end - - hosts[evaluator.authority] = evaluator - end - - Console.info(self) {"Hosts: #{hosts}"} - - return hosts - end - def configuration - configuration = super - hosts = host_map(configuration.environments) - - Configuration.new.tap do |configuration| - environment = self.environment(hosts: hosts) - configuration.add(environment) - end - end - - # The container class to use. - def container_class - Async::Container.best_container_class + Configuration.for( + self.environment(environments: super.environments) + ) end # Prepare the environment and run the controller. @@ -90,7 +61,7 @@ def call end end - Async::Service::Controller.run(self.configuration, container_class: self.container_class) + Async::Service::Controller.run(self.configuration) end # The endpoint to bind to. diff --git a/lib/falcon/command/redirect.rb b/lib/falcon/command/redirect.rb index a44ef0a1..12d29deb 100644 --- a/lib/falcon/command/redirect.rb +++ b/lib/falcon/command/redirect.rb @@ -41,33 +41,10 @@ def environment(**options) ) end - def host_map(environments) - hosts = {} - - environments.each do |environment| - next unless environment.implements?(Falcon::Environment::Application) - evaluator = environment.evaluator - hosts[evaluator.authority] = evaluator - end - - Console.info(self) {"Hosts: #{hosts}"} - - return hosts - end - def configuration - configuration = super - hosts = host_map(configuration.environments) - - Configuration.new.tap do |configuration| - environment = self.environment(hosts: hosts) - configuration.add(environment) - end - end - - # The container class to use. - def container_class - Async::Container.best_container_class + Configuration.for( + self.environment(environments: super.environments) + ) end # Prepare the environment and run the controller. @@ -83,7 +60,7 @@ def call end end - Async::Service::Controller.run(self.configuration, container_class: self.container_class) + Async::Service::Controller.run(self.configuration) end # The endpoint to bind to. diff --git a/lib/falcon/environment/proxy.rb b/lib/falcon/environment/proxy.rb index c34f5cbe..386b7e4b 100644 --- a/lib/falcon/environment/proxy.rb +++ b/lib/falcon/environment/proxy.rb @@ -35,15 +35,15 @@ def hosts environments.each do |environment| evaluator = environment.evaluator + # next unless environment.implements?(Falcon::Environment::Application) if evaluator.key?(:authority) and evaluator.key?(:ssl_context) and evaluator.key?(:endpoint) - Console.logger.info(self) {"Proxying #{self.url} to #{evaluator.authority} using #{evaluator.endpoint}"} + Console.info(self) {"Proxying #{self.url} to #{evaluator.authority} using #{evaluator.endpoint}"} hosts[evaluator.authority] = evaluator - # Pre-cache the ssl contexts: - # It seems some OpenSSL objects don't like event-driven I/O. - # service.ssl_context - else - Console.logger.warn(self) {"Ignoring environment: #{environment}, missing authority, ssl_context, or endpoint."} + if RUBY_VERSION < '3.1' + # Ensure the SSL context is set up before forking - it's buggy on Ruby < 3.1: + evaluator.ssl_context + end end end diff --git a/lib/falcon/environment/redirect.rb b/lib/falcon/environment/redirect.rb index 06f7d8ce..b6ad0bd0 100644 --- a/lib/falcon/environment/redirect.rb +++ b/lib/falcon/environment/redirect.rb @@ -20,8 +20,25 @@ def redirect_endpoint Async::HTTP::Endpoint.parse(redirect_url) end + # The services we will redirect to. + # @returns [Array(Async::Service::Environment)] + def environments + [] + end + 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 # Load the {Middleware::Redirect} application with the specified hosts.