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. scheme
  8. verify_hostname
  9. write

Constants

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

Public Class methods

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

Public Instance methods

close ()
[show source]
   # File lib/httpx/io/ssl.rb
38 def close
39   super
40   # allow reconnections
41   # connect only works if initial @io is a socket
42   @io = @io.io if @io.respond_to?(:io)
43   @negotiated = false
44 end
connect ()
[show source]
   # File lib/httpx/io/ssl.rb
50 def connect
51   super
52   if @keep_open
53     @state = :negotiated
54     return
55   end
56   return if @state == :negotiated ||
57             @state != :connected
58 
59   unless @io.is_a?(OpenSSL::SSL::SSLSocket)
60     @io = OpenSSL::SSL::SSLSocket.new(@io, @ctx)
61     @io.hostname = @hostname
62     @io.sync_close = true
63   end
64   @io.connect_nonblock
65   @io.post_connection_check(@hostname) if @ctx.verify_mode != OpenSSL::SSL::VERIFY_NONE
66   transition(:negotiated)
67 rescue ::IO::WaitReadable,
68        ::IO::WaitWritable
69 end
connected? ()
[show source]
   # File lib/httpx/io/ssl.rb
46 def connected?
47   @state == :negotiated
48 end
inspect ()
[show source]
    # File lib/httpx/io/ssl.rb
 97 def inspect
 98   id = @io.closed? ? "closed" : @io.to_io.fileno
 99   "#<SSL(fd: #{id}): #{@ip}:#{@port} state: #{@state}>"
100 end
protocol ()
[show source]
   # File lib/httpx/io/ssl.rb
25 def protocol
26   @io.alpn_protocol || super
27 rescue StandardError
28   super
29 end
read (*)
[show source]
   # File lib/httpx/io/ssl.rb
72 def read(*)
73   super
74 rescue ::IO::WaitWritable
75   0
76 end
scheme ()
[show source]
   # File lib/httpx/io/ssl.rb
21 def scheme
22   "https"
23 end
verify_hostname (host)
[show source]
   # File lib/httpx/io/ssl.rb
31 def verify_hostname(host)
32   return false if @ctx.verify_mode == OpenSSL::SSL::VERIFY_NONE
33   return false if @io.peer_cert.nil?
34 
35   OpenSSL::SSL.verify_certificate_identity(@io.peer_cert, host)
36 end
write (*)
[show source]
   # File lib/httpx/io/ssl.rb
78 def write(*)
79   super
80 rescue ::IO::WaitReadable
81   0
82 end