lib/httpx/io/ssl.rb in httpx-0.12.0 vs lib/httpx/io/ssl.rb in httpx-0.13.0
- old
+ new
@@ -45,33 +45,34 @@
@state == :negotiated
end
def connect
super
- if @keep_open
- @state = :negotiated
- return
- end
return if @state == :negotiated ||
@state != :connected
unless @io.is_a?(OpenSSL::SSL::SSLSocket)
@io = OpenSSL::SSL::SSLSocket.new(@io, @ctx)
@io.hostname = @sni_hostname
@io.sync_close = true
end
- @io.connect_nonblock
- @io.post_connection_check(@sni_hostname) if @ctx.verify_mode != OpenSSL::SSL::VERIFY_NONE
- transition(:negotiated)
- @interests = :w
- rescue ::IO::WaitReadable
- @interests = :r
- rescue ::IO::WaitWritable
- @interests = :w
+ try_ssl_connect
end
if RUBY_VERSION < "2.3"
+ # :nocov:
+ def try_ssl_connect
+ @io.connect_nonblock
+ @io.post_connection_check(@sni_hostname) if @ctx.verify_mode != OpenSSL::SSL::VERIFY_NONE
+ transition(:negotiated)
+ @interests = :w
+ rescue ::IO::WaitReadable
+ @interests = :r
+ rescue ::IO::WaitWritable
+ @interests = :w
+ end
+
def read(_, buffer)
super
rescue ::IO::WaitWritable
buffer.clear
0
@@ -80,11 +81,27 @@
def write(*)
super
rescue ::IO::WaitReadable
0
end
+ # :nocov:
else
+ def try_ssl_connect
+ case @io.connect_nonblock(exception: false)
+ when :wait_readable
+ @interests = :r
+ return
+ when :wait_writable
+ @interests = :w
+ return
+ end
+ @io.post_connection_check(@sni_hostname) if @ctx.verify_mode != OpenSSL::SSL::VERIFY_NONE
+ transition(:negotiated)
+ @interests = :w
+ end
+
+ # :nocov:
if OpenSSL::VERSION < "2.0.6"
def read(size, buffer)
@io.read_nonblock(size, buffer)
buffer.bytesize
rescue ::IO::WaitReadable,
@@ -93,14 +110,10 @@
0
rescue EOFError
nil
end
end
- end
-
- def inspect
- id = @io.closed? ? "closed" : @io.to_io.fileno
- "#<SSL(fd: #{id}): #{@ip}:#{@port} state: #{@state}>"
+ # :nocov:
end
private
def transition(nextstate)