HTTPGenericRequest is the parent of the Net::HTTPRequest class.

Do not use this directly; instead, use a subclass of Net::HTTPRequest.

About the Examples

Attributes
Read

Returns the string method name for the request:

Net::HTTP::Get.new(uri).method  # => "GET"
Net::HTTP::Post.new(uri).method # => "POST"
Read

Returns the string path for the request:

Net::HTTP::Get.new(uri).path # => "/"
Net::HTTP::Post.new('example.com').path # => "example.com"

uri

Read

Returns the URI object for the request, or nil if none:

Net::HTTP::Get.new(uri).uri
# => #<URI::HTTPS https://jsonplaceholder.typicode.com/>
Net::HTTP::Get.new('example.com').uri # => nil

Returns false if the request’s header 'Accept-Encoding' has been set manually or deleted (indicating that the user intends to handle encoding in the response), true otherwise:

req = Net::HTTP::Get.new(uri) # => #<Net::HTTP::Get GET>
req['Accept-Encoding']        # => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
req.decode_content            # => true
req['Accept-Encoding'] = 'foo'
req.decode_content            # => false
req.delete('Accept-Encoding')
req.decode_content            # => false
Read

Returns the string body for the request, or nil if there is none:

req = Net::HTTP::Post.new(uri)
req.body # => nil
req.body = '{"title": "foo","body": "bar","userId": 1}'
req.body # => "{\"title\": \"foo\",\"body\": \"bar\",\"userId\": 1}"

Returns the body stream object for the request, or nil if there is none:

req = Net::HTTP::Post.new(uri)          # => #<Net::HTTP::Post POST>
req.body_stream                         # => nil
require 'stringio'
req.body_stream = StringIO.new('xyzzy') # => #<StringIO:0x0000027d1e5affa8>
req.body_stream                         # => #<StringIO:0x0000027d1e5affa8>
Instance Methods

Sets the body for the request:

req = Net::HTTP::Post.new(uri)
req.body # => nil
req.body = '{"title": "foo","body": "bar","userId": 1}'
req.body # => "{\"title\": \"foo\",\"body\": \"bar\",\"userId\": 1}"

Sets the body stream for the request:

req = Net::HTTP::Post.new(uri)          # => #<Net::HTTP::Post POST>
req.body_stream                         # => nil
require 'stringio'
req.body_stream = StringIO.new('xyzzy') # => #<StringIO:0x0000027d1e5affa8>
req.body_stream                         # => #<StringIO:0x0000027d1e5affa8>
No documentation available
No documentation available

Returns a string representation of the request:

Net::HTTP::Post.new(uri).inspect # => "#<Net::HTTP::Post POST>"
No documentation available

Returns whether the request may have a body:

Net::HTTP::Post.new(uri).request_body_permitted? # => true
Net::HTTP::Get.new(uri).request_body_permitted?  # => false

Returns whether the response may have a body:

Net::HTTP::Post.new(uri).response_body_permitted? # => true
Net::HTTP::Head.new(uri).response_body_permitted? # => false
No documentation available
No documentation available
No documentation available
No documentation available

Waits up to the continue timeout for a response from the server provided we’re speaking HTTP 1.1 and are expecting a 100-continue response.

No documentation available