Skip to content

Commit

Permalink
Adjust code for compiling without SSL
Browse files Browse the repository at this point in the history
  • Loading branch information
MSP-Greg committed Jul 7, 2020
1 parent e2b4193 commit 6a2140c
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
19 changes: 14 additions & 5 deletions lib/puma/binder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

require 'puma/const'
require 'puma/util'
require 'puma/minissl/context_builder'
require 'puma/configuration'

module Puma
Expand All @@ -14,6 +13,8 @@ class Binder

RACK_VERSION = [1,6].freeze

@@minissl_loaded = false

def initialize(events, conf = Configuration.new)
@events = events
@listeners = []
Expand Down Expand Up @@ -155,6 +156,9 @@ def parse(binds, logger, log_msg = 'Listening')

@listeners << [str, io]
when "ssl"

load_ssl unless @@minissl_loaded

params = Util.parse_query uri.query
ctx = MiniSSL::ContextBuilder.new(params, @events).context

Expand Down Expand Up @@ -245,9 +249,8 @@ def inherit_tcp_listener(host, port, fd)

def add_ssl_listener(host, port, ctx,
optimize_for_latency=true, backlog=1024)
require 'puma/minissl'

MiniSSL.check
load_ssl unless @@minissl_loaded

if host == "localhost"
loopback_addresses.each do |addr|
Expand All @@ -264,7 +267,6 @@ def add_ssl_listener(host, port, ctx,
s.setsockopt(Socket::SOL_SOCKET,Socket::SO_REUSEADDR, true)
s.listen backlog


ssl = MiniSSL::Server.new s, ctx
env = @proto_env.dup
env[HTTPS_KEY] = HTTPS
Expand All @@ -276,7 +278,6 @@ def add_ssl_listener(host, port, ctx,

def inherit_ssl_listener(fd, ctx)
require 'puma/minissl'
MiniSSL.check

if fd.kind_of? TCPServer
s = fd
Expand Down Expand Up @@ -384,5 +385,13 @@ def loopback_addresses
def socket_activation_fd(int)
int + 3 # 3 is the magic number you add to follow the SA protocol
end

def load_ssl
@@minissl_loaded = true
require 'puma/minissl/context_builder'
require 'puma/accept_nonblock'
require 'puma/minissl'
MiniSSL.check
end
end
end
1 change: 1 addition & 0 deletions lib/puma/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module WaitReadable
end

require 'puma/detect'
require 'puma/puma_http11'
require 'tempfile'
require 'forwardable'

Expand Down
3 changes: 1 addition & 2 deletions lib/puma/minissl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

module Puma
module MiniSSL

# define constant at runtime, as it's easy to determine at built time,
# but Puma could (it shouldn't) be loaded with an older OpenSSL version
HAS_TLS1_3 = !IS_JRUBY &&
Expand Down Expand Up @@ -308,5 +307,5 @@ def close
@socket.close unless @socket.closed? # closed? call is for Windows
end
end
end
end if IS_JRUBY || (Puma::MiniSSL.check.nil? rescue nil)
end
3 changes: 0 additions & 3 deletions lib/puma/minissl/context_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ module Puma
module MiniSSL
class ContextBuilder
def initialize(params, events)
require 'puma/minissl'
MiniSSL.check

@params = params
@events = events
end
Expand Down
2 changes: 2 additions & 0 deletions lib/puma/reactor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require 'puma/util'
require 'puma/minissl'

# nio4r v2.5.2 uses OpenSSL, but doesn't load it. Fixed in next release
require 'openssl' if Puma::IS_WINDOWS
require 'nio'

module Puma
Expand Down
4 changes: 0 additions & 4 deletions lib/puma/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@
require 'puma/null_io'
require 'puma/reactor'
require 'puma/client'
require 'puma/binder'
require 'puma/accept_nonblock'
require 'puma/util'
require 'puma/io_buffer'

require 'puma/puma_http11'

require 'socket'
require 'forwardable'

Expand Down

0 comments on commit 6a2140c

Please sign in to comment.