lib/falcon/hosts.rb in falcon-0.32.0 vs lib/falcon/hosts.rb in falcon-0.32.1

- old
+ new

@@ -18,86 +18,19 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. require 'async/io/endpoint' +require_relative 'host' require_relative 'proxy' require_relative 'redirection' require 'async/container' require 'async/container/controller' require 'async/http/endpoint' module Falcon - class Host - def initialize(environment) - @environment = environment.flatten - @evaluator = @environment.evaluator - end - - def name - "Falcon Host for #{self.authority}" - end - - def authority - @evaluator.authority - end - - def endpoint - @evaluator.endpoint - end - - def ssl_context - @evaluator.ssl_context - end - - def root - @evaluator.root - end - - def bound_endpoint - @evaluator.bound_endpoint - end - - def to_s - "\#<#{self.class} #{@evaluator.authority}>" - end - - def assume_privileges(path) - stat = File.stat(path) - - Process::GID.change_privilege(stat.gid) - Process::UID.change_privilege(stat.uid) - end - - def spawn(container) - container.spawn(name: self.name, restart: true) do |instance| - path = File.join(self.root, "falcon.rb") - - assume_privileges(path) - - instance.exec("bundle", "exec", path) - end - end - - def run(container) - if @environment.include?(:server) - bound_endpoint = self.bound_endpoint - - container.run(name: self.name, restart: true) do |task, instance| - Async.logger.info(self) {"Starting application server..."} - - server = @evaluator.server - - server.run - - task.children.each(&:wait) - end - end - end - end - class Hosts DEFAULT_ALPN_PROTOCOLS = ['h2', 'http/1.1'].freeze SERVER_CIPHERS = "EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5".freeze def initialize(configuration) @@ -164,11 +97,11 @@ def redirection(secure_endpoint) Redirection.new(Falcon::BadRequest, @named, secure_endpoint) end - def run(container = Async::Container::Forked.new, **options) + def run(container = Async::Container.new, **options) @named.each do |name, host| host.spawn(container) end secure_endpoint = Async::HTTP::Endpoint.parse(options[:bind_secure], ssl_context: self.ssl_context) @@ -193,9 +126,14 @@ redirection = self.redirection(secure_endpoint) redirection_server = Falcon::Server.new(redirection, insecure_endpoint_bound, insecure_endpoint.protocol, insecure_endpoint.scheme) redirection_server.run + end + + container.attach do + secure_endpoint_bound.close + insecure_endpoint_bound.close end return container end end