class HTTPX::SSL

  1. lib/httpx/io/ssl.rb
  2. lib/httpx/plugins/proxy/ssh.rb
  3. show all
Superclass: TCP

Methods

Public Class

  1. new

Public Instance

  1. close
  2. connect
  3. connected?
  4. inspect
  5. protocol
  6. read
  7. verify_hostname
  8. write

Constants

TLS_OPTIONS = if OpenSSL::SSL::SSLContext.instance_methods.include?(:alpn_protocols) { alpn_protocols: %w[h2 http/1.1] } else # :nocov: {} # :nocov: end  

Public Class methods

new (_, _, options)
[show source]
   # File lib/httpx/io/ssl.rb
15 def initialize(_, _, options)
16   @ctx = OpenSSL::SSL::SSLContext.new
17   ctx_options = TLS_OPTIONS.merge(options.ssl)
18   @ctx.set_params(ctx_options) unless ctx_options.empty?
19   super
20   @state = :negotiated if @keep_open
21 end

Public Instance methods

close ()
[show source]
   # File lib/httpx/io/ssl.rb
36 def close
37   super
38   # allow reconnections
39   # connect only works if initial @io is a socket
40   @io = @io.io if @io.respond_to?(:io)
41   @negotiated = false
42 end
connect ()
[show source]
   # File lib/httpx/io/ssl.rb
48 def connect
49   super
50   if @keep_open
51     @state = :negotiated
52     return
53   end
54   return if @state == :negotiated ||
55             @state != :connected
56 
57   unless @io.is_a?(OpenSSL::SSL::SSLSocket)
58     @io = OpenSSL::SSL::SSLSocket.new(@io, @ctx)
59     @io.hostname = @hostname
60     @io.sync_close = true
61   end
62   @io.connect_nonblock
63   @io.post_connection_check(@hostname) if @ctx.verify_mode != OpenSSL::SSL::VERIFY_NONE
64   transition(:negotiated)
65 rescue ::IO::WaitReadable,
66        ::IO::WaitWritable
67 end
connected? ()
[show source]
   # File lib/httpx/io/ssl.rb
44 def connected?
45   @state == :negotiated
46 end
inspect ()

:nocov:

[show source]
    # File lib/httpx/io/ssl.rb
 98 def inspect
 99   id = @io.closed? ? "closed" : @io.to_io.fileno
100   "#<SSL(fd: #{id}): #{@ip}:#{@port} state: #{@state}>"
101 end
protocol ()
[show source]
   # File lib/httpx/io/ssl.rb
23 def protocol
24   @io.alpn_protocol || super
25 rescue StandardError
26   super
27 end
read (*)
[show source]
   # File lib/httpx/io/ssl.rb
71 def read(*)
72   super
73 rescue ::IO::WaitWritable
74   0
75 end
verify_hostname (host)
[show source]
   # File lib/httpx/io/ssl.rb
29 def verify_hostname(host)
30   return false if @ctx.verify_mode == OpenSSL::SSL::VERIFY_NONE
31   return false if !@io.respond_to?(:peer_cert) || @io.peer_cert.nil?
32 
33   OpenSSL::SSL.verify_certificate_identity(@io.peer_cert, host)
34 end
write (*)
[show source]
   # File lib/httpx/io/ssl.rb
77 def write(*)
78   super
79 rescue ::IO::WaitReadable
80   0
81 end