diff --git a/lib/puma.rb b/lib/puma.rb index cdbefef870..497e22f1a5 100644 --- a/lib/puma.rb +++ b/lib/puma.rb @@ -19,6 +19,24 @@ module Puma autoload :Server, 'puma/server' autoload :Launcher, 'puma/launcher' + # at present, MiniSSL::Engine is only defined in extension code (puma_http11), + # not in minissl.rb + HAS_SSL = const_defined?(:MiniSSL, false) && MiniSSL.const_defined?(:Engine, false) + + if HAS_SSL + require 'puma/minissl' + else + module MiniSSL + # this class is defined so that it exists when Puma is compiled + # without ssl support, as Server and Reactor use it in rescue statements. + class SSLError < StandardError ; end + end + end + + def self.ssl? + HAS_SSL + end + # @!attribute [rw] stats_object= def self.stats_object=(val) @get_stats = val @@ -40,12 +58,4 @@ def self.set_thread_name(name) return unless Thread.current.respond_to?(:name=) Thread.current.name = "puma #{name}" end - - unless HAS_SSL - module MiniSSL - # this class is defined so that it exists when Puma is compiled - # without ssl support, as Server and Reactor use it in rescue statements. - class SSLError < StandardError ; end - end - end end diff --git a/lib/puma/detect.rb b/lib/puma/detect.rb index 05d5384f16..c85a359704 100644 --- a/lib/puma/detect.rb +++ b/lib/puma/detect.rb @@ -1,32 +1,36 @@ # frozen_string_literal: true +# This file can be loaded independently of puma.rb, so it cannot have any code +# that assumes puma.rb is loaded. + + module Puma - # at present, MiniSSL::Engine is only defined in extension code, not in minissl.rb - HAS_SSL = const_defined?(:MiniSSL, false) && MiniSSL.const_defined?(:Engine, false) + # @version 5.2.1 + HAS_FORK = ::Process.respond_to? :fork - def self.ssl? - HAS_SSL - end + IS_JRUBY = Object.const_defined? :JRUBY_VERSION - IS_JRUBY = defined?(JRUBY_VERSION) + IS_WINDOWS = !!(RUBY_PLATFORM =~ /mswin|ming|cygwin/ || + IS_JRUBY && RUBY_DESCRIPTION =~ /mswin/) + + # @version 5.2.0 + IS_MRI = (RUBY_ENGINE == 'ruby' || RUBY_ENGINE.nil?) def self.jruby? IS_JRUBY end - IS_WINDOWS = RUBY_PLATFORM =~ /mswin|ming|cygwin/ - def self.windows? IS_WINDOWS end # @version 5.0.0 def self.mri? - RUBY_ENGINE == 'ruby' || RUBY_ENGINE.nil? + IS_MRI end # @version 5.0.0 def self.forkable? - ::Process.respond_to?(:fork) + HAS_FORK end end