Skip to content

Commit

Permalink
Move ssl detection to puma.rb
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 committed Jan 29, 2021
1 parent f7f58ae commit 82efac7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 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
18 changes: 9 additions & 9 deletions lib/puma/detect.rb
@@ -1,28 +1,28 @@
# frozen_string_literal: true

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)
# This file can be loaded independently of puma.rb, so it cannot have any code
# that assumes puma.rb is loaded.

def self.ssl?
HAS_SSL
end

module Puma
IS_JRUBY = defined?(JRUBY_VERSION)

IS_WINDOWS = RUBY_PLATFORM =~ /mswin|mingw|cygwin/

# @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
Expand Down

0 comments on commit 82efac7

Please sign in to comment.