lib/httpx/io/ssl.rb in httpx-0.10.2 vs lib/httpx/io/ssl.rb in httpx-0.11.0
- old
+ new
@@ -5,20 +5,20 @@
module HTTPX
class SSL < TCP
TLS_OPTIONS = if OpenSSL::SSL::SSLContext.instance_methods.include?(:alpn_protocols)
{ alpn_protocols: %w[h2 http/1.1] }
else
- # :nocov:
{}
- # :nocov:
end
def initialize(_, _, options)
@ctx = OpenSSL::SSL::SSLContext.new
ctx_options = TLS_OPTIONS.merge(options.ssl)
+ @tls_hostname = ctx_options.delete(:hostname)
@ctx.set_params(ctx_options) unless ctx_options.empty?
super
+ @tls_hostname ||= @hostname
@state = :negotiated if @keep_open
end
def interests
@interests || super
@@ -57,23 +57,22 @@
return if @state == :negotiated ||
@state != :connected
unless @io.is_a?(OpenSSL::SSL::SSLSocket)
@io = OpenSSL::SSL::SSLSocket.new(@io, @ctx)
- @io.hostname = @hostname
+ @io.hostname = @tls_hostname
@io.sync_close = true
end
@io.connect_nonblock
- @io.post_connection_check(@hostname) if @ctx.verify_mode != OpenSSL::SSL::VERIFY_NONE
+ @io.post_connection_check(@tls_hostname) if @ctx.verify_mode != OpenSSL::SSL::VERIFY_NONE
transition(:negotiated)
rescue ::IO::WaitReadable
@interests = :r
rescue ::IO::WaitWritable
@interests = :w
end
- # :nocov:
if RUBY_VERSION < "2.3"
def read(_, buffer)
super
rescue ::IO::WaitWritable
buffer.clear
@@ -97,17 +96,14 @@
rescue EOFError
nil
end
end
end
- # :nocov:
- # :nocov:
def inspect
id = @io.closed? ? "closed" : @io.to_io.fileno
"#<SSL(fd: #{id}): #{@ip}:#{@port} state: #{@state}>"
end
- # :nocov:
private
def transition(nextstate)
case nextstate