Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Net::HTTP#write_timeout=
(::Float | ::Integer write_timeout) -> (::Float | ::Integer)
write_timeout=(sec)
lib/net/http.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/net/http.rb, line 1446
def write_timeout=(sec)
@socket.write_timeout = sec if @socket
@write_timeout = sec
end
Sets the write timeout, in seconds, for self to integer sec; the initial value is 60.
Argument sec must be a non-negative numeric value:
Example
_uri = uri.dup _uri.path = '/posts' body = 'bar' * 200000 data = <<EOF {"title": "foo", "body": "#{body}", "userId": "1"} EOF headers = {'content-type': 'application/json'} http = Net::HTTP.new(hostname) http.write_timeout # => 60 http.post(_uri.path, data, headers) # => #<Net::HTTPCreated 201 Created readbody=true> http.write_timeout = 0 http.post(_uri.path, data, headers) # Raises Net::WriteTimeout.