Class: HTTPX::SSL
Direct Known Subclasses
Constant Summary collapse
- TLS_OPTIONS =
if OpenSSL::SSL::SSLContext.instance_methods.include?(:alpn_protocols) { alpn_protocols: %w[h2 http/1.1] } else {} end
Constants included from Loggable
Instance Attribute Summary
Attributes inherited from TCP
Instance Method Summary collapse
- #close ⇒ Object
- #connect ⇒ Object
- #connected? ⇒ Boolean
-
#initialize(_, options) ⇒ SSL
constructor
A new instance of SSL.
- #inspect ⇒ Object
- #protocol ⇒ Object
- #read(size, buffer) ⇒ Object
- #scheme ⇒ Object
- #write ⇒ Object
Methods inherited from TCP
Methods included from Loggable
Constructor Details
#initialize(_, options) ⇒ SSL
Returns a new instance of SSL.
13 14 15 16 17 18 19 |
# File 'lib/httpx/io/ssl.rb', line 13 def initialize(_, ) @ctx = OpenSSL::SSL::SSLContext.new = TLS_OPTIONS.merge(.ssl) @ctx.set_params() unless .empty? super @state = :negotiated if @keep_open end |
Instance Method Details
#close ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/httpx/io/ssl.rb', line 31 def close super # allow reconnections # connect only works if initial @io is a socket @io = @io.io if @io.respond_to?(:io) @negotiated = false end |
#connect ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/httpx/io/ssl.rb', line 43 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 = @hostname @io.sync_close = true end @io.connect_nonblock @io.post_connection_check(@hostname) if @ctx.verify_mode != OpenSSL::SSL::VERIFY_NONE transition(:negotiated) rescue ::IO::WaitReadable, ::IO::WaitWritable end |
#connected? ⇒ Boolean
39 40 41 |
# File 'lib/httpx/io/ssl.rb', line 39 def connected? @state == :negotiated end |
#inspect ⇒ Object
89 90 91 92 |
# File 'lib/httpx/io/ssl.rb', line 89 def inspect id = @io.closed? ? "closed" : @io.to_io.fileno "#<SSL(fd: #{id}): #{@ip}:#{@port} state: #{@state}>" end |
#protocol ⇒ Object
25 26 27 28 29 |
# File 'lib/httpx/io/ssl.rb', line 25 def protocol @io.alpn_protocol || super rescue StandardError super end |
#read(size, buffer) ⇒ Object
64 65 66 67 68 |
# File 'lib/httpx/io/ssl.rb', line 64 def read(*) super rescue ::IO::WaitWritable 0 end |
#scheme ⇒ Object
21 22 23 |
# File 'lib/httpx/io/ssl.rb', line 21 def scheme "https" end |
#write ⇒ Object
70 71 72 73 74 |
# File 'lib/httpx/io/ssl.rb', line 70 def write(*) super rescue ::IO::WaitReadable 0 end |