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.
156 157 158 159 160 161 162 |
# File 'lib/httpx/io.rb', line 156 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
174 175 176 177 178 179 180 |
# File 'lib/httpx/io.rb', line 174 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
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/httpx/io.rb', line 186 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 # TODO: this might block it all @io.connect_nonblock transition(:negotiated) rescue ::IO::WaitReadable, ::IO::WaitWritable end |
#connected? ⇒ Boolean
182 183 184 |
# File 'lib/httpx/io.rb', line 182 def connected? @state == :negotiated end |
#inspect ⇒ Object
232 233 234 235 |
# File 'lib/httpx/io.rb', line 232 def inspect id = @io.closed? ? "closed" : @io.to_io.fileno "#<SSL(fd: #{id}): #{@ip}:#{@port} state: #{@state}>" end |
#protocol ⇒ Object
168 169 170 171 172 |
# File 'lib/httpx/io.rb', line 168 def protocol @io.alpn_protocol || super rescue StandardError super end |
#read(size, buffer) ⇒ Object
207 208 209 210 211 |
# File 'lib/httpx/io.rb', line 207 def read(*) super rescue ::IO::WaitWritable 0 end |
#scheme ⇒ Object
164 165 166 |
# File 'lib/httpx/io.rb', line 164 def scheme "https" end |
#write ⇒ Object
213 214 215 216 217 |
# File 'lib/httpx/io.rb', line 213 def write(*) super rescue ::IO::WaitReadable 0 end |