Skip to content

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)

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.
See also #use_ssl? #use_ssl= also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0