Skip to content

Commit

Permalink
Move ssl detection to puma.rb (puma#2541)
Browse files Browse the repository at this point in the history
puma.rb loads puma/puma_http11, which contains the compiled c code for ssl.  Move ssl detection from puma/detect.rb to puma.rb
  • Loading branch information
MSP-Greg authored and JuanitoFatas committed Sep 9, 2022
1 parent e5a2fd9 commit ec05975
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
26 changes: 18 additions & 8 deletions lib/puma.rb
Expand Up @@ -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
Expand All @@ -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
24 changes: 14 additions & 10 deletions 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

0 comments on commit ec05975

Please sign in to comment.