Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move ssl detection to puma.rb [changelog skip] #2541

Merged
merged 1 commit into from Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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