Class: HTTP::Timeout::Null
- Inherits:
-
Object
- Object
- HTTP::Timeout::Null
- Defined in:
- lib/http/timeout/null.rb
Overview
Base timeout handler with no timeout enforcement
Direct Known Subclasses
Constant Summary collapse
- NATIVE_CONNECT_TIMEOUT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Whether TCPSocket natively supports connect_timeout and Happy Eyeballs (RFC 8305). Available in Ruby 3.4+.
RUBY_VERSION >= "3.4"
Instance Attribute Summary collapse
-
#options ⇒ Hash
readonly
Timeout configuration options.
-
#socket ⇒ Object
readonly
The underlying socket.
Instance Method Summary collapse
-
#close ⇒ void
Closes the underlying socket.
-
#closed? ⇒ Boolean
Checks whether the socket is closed.
-
#connect(socket_class, host, port, nodelay: false) ⇒ void
Connects to a socket.
-
#connect_ssl ⇒ void
Starts a SSL connection on a socket.
-
#initialize(read_timeout: nil, write_timeout: nil, connect_timeout: nil, global_timeout: nil) ⇒ HTTP::Timeout::Null
constructor
Initializes the null timeout handler.
-
#readpartial(size, buffer = nil) ⇒ String, :eof
Read from the socket.
-
#start_tls(host, ssl_socket_class, ssl_context) ⇒ void
Configures the SSL connection and starts it.
-
#write(data) ⇒ Integer
(also: #<<)
Write to the socket.
Constructor Details
#initialize(read_timeout: nil, write_timeout: nil, connect_timeout: nil, global_timeout: nil) ⇒ HTTP::Timeout::Null
Initializes the null timeout handler
46 47 48 49 |
# File 'lib/http/timeout/null.rb', line 46 def initialize(read_timeout: nil, write_timeout: nil, connect_timeout: nil, global_timeout: nil) @options = { read_timeout: read_timeout, write_timeout: write_timeout, connect_timeout: connect_timeout, global_timeout: global_timeout }.compact end |
Instance Attribute Details
#options ⇒ Hash (readonly)
Timeout configuration options
24 25 26 |
# File 'lib/http/timeout/null.rb', line 24 def @options end |
#socket ⇒ Object (readonly)
The underlying socket
33 34 35 |
# File 'lib/http/timeout/null.rb', line 33 def socket @socket end |
Instance Method Details
#close ⇒ void
This method returns an undefined value.
Closes the underlying socket
85 86 87 |
# File 'lib/http/timeout/null.rb', line 85 def close @socket&.close end |
#closed? ⇒ Boolean
Checks whether the socket is closed
96 97 98 |
# File 'lib/http/timeout/null.rb', line 96 def closed? @socket&.closed? end |
#connect(socket_class, host, port, nodelay: false) ⇒ void
This method returns an undefined value.
Connects to a socket
62 63 64 65 |
# File 'lib/http/timeout/null.rb', line 62 def connect(socket_class, host, port, nodelay: false) @socket = open_socket(socket_class, host, port) @socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) if nodelay end |
#connect_ssl ⇒ void
This method returns an undefined value.
Starts a SSL connection on a socket
74 75 76 |
# File 'lib/http/timeout/null.rb', line 74 def connect_ssl @socket.connect end |
#readpartial(size, buffer = nil) ⇒ String, :eof
Read from the socket
132 133 134 135 136 |
# File 'lib/http/timeout/null.rb', line 132 def readpartial(size, buffer = nil) @socket.readpartial(size, buffer) rescue EOFError :eof end |
#start_tls(host, ssl_socket_class, ssl_context) ⇒ void
This method returns an undefined value.
Configures the SSL connection and starts it
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/http/timeout/null.rb', line 110 def start_tls(host, ssl_socket_class, ssl_context) @socket = ssl_socket_class.new(socket, ssl_context) @socket.hostname = host if @socket.respond_to? :hostname= @socket.sync_close = true if @socket.respond_to? :sync_close= connect_ssl return unless ssl_context.verify_mode == OpenSSL::SSL::VERIFY_PEER return if ssl_context.respond_to?(:verify_hostname) && !ssl_context.verify_hostname @socket.post_connection_check(host) end |
#write(data) ⇒ Integer Also known as: <<
Write to the socket
146 147 148 |
# File 'lib/http/timeout/null.rb', line 146 def write(data) @socket.write(data) end |