Class: Gem::Net::HTTPRequest
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
Gem::Net::HTTP::Copy, Gem::Net::HTTP::Delete, Gem::Net::HTTP::Get, Gem::Net::HTTP::Head, Gem::Net::HTTP::Lock, Gem::Net::HTTP::Mkcol, Gem::Net::HTTP::Move, Gem::Net::HTTP::Options, Gem::Net::HTTP::Patch, Gem::Net::HTTP::Post, Gem::Net::HTTP::Propfind, Gem::Net::HTTP::Proppatch, Gem::Net::HTTP::Put, Gem::Net::HTTP::Trace, Gem::Net::HTTP::Unlock
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
HTTPGenericRequest
|
|
Instance Chain:
self,
HTTPGenericRequest ,
HTTPHeader
|
|
Inherits: |
Gem::Net::HTTPGenericRequest
|
Defined in: | lib/rubygems/vendor/net-http/lib/net/http/request.rb |
Overview
This class is the base class for Gem::Net::HTTP request classes. The class should not be used directly; instead you should use its subclasses, listed below.
Creating a Request
An request object may be created with either a ::Gem::URI
or a string hostname:
require 'rubygems/vendor/net-http/lib/net/http'
uri = Gem::URI('https://jsonplaceholder.typicode.com/')
req = Gem::Net::HTTP::Get.new(uri) # => #<Gem::Net::HTTP::Get GET>
req = Gem::Net::HTTP::Get.new(uri.hostname) # => #<Gem::Net::HTTP::Get GET>
And with any of the subclasses:
req = Gem::Net::HTTP::Head.new(uri) # => #<Gem::Net::HTTP::Head HEAD>
req = Gem::Net::HTTP::Post.new(uri) # => #<Gem::Net::HTTP::Post POST>
req = Gem::Net::HTTP::Put.new(uri) # => #<Gem::Net::HTTP::Put PUT>
# ...
The new instance is suitable for use as the argument to HTTP#request.
Request Headers
A new request object has these header fields by default:
req.to_hash
# =>
{"accept-encoding"=>["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"],
"accept"=>["*/*"],
"user-agent"=>["Ruby"],
"host"=>["jsonplaceholder.typicode.com"]}
See:
-
{Gem::Request header Accept-Encoding} and
Compression and Decompression
. -
{Gem::Request header Accept}.
-
{Gem::Request header User-Agent}.
-
{Gem::Request header Host}.
You can add headers or override default headers:
# res = Gem::Net::HTTP::Get.new(uri, {'foo' => '0', 'bar' => '1'})
This class (and therefore its subclasses) also includes (indirectly) module HTTPHeader
, which gives access to its methods for setting headers
.
Request Subclasses
Subclasses for HTTP
requests:
Subclasses for WebDAV requests:
Constant Summary
HTTPHeader
- Included
Class Method Summary
- .new(path, initheader = nil) ⇒ HTTPRequest constructor
HTTPGenericRequest
- Inherited
Instance Attribute Summary
HTTPGenericRequest
- Inherited
#body | Returns the string body for the request, or |
#body= | Sets the body for the request: |
#body_stream | Returns the body stream object for the request, or |
#body_stream= | Sets the body stream for the request: |
#decode_content | Returns |
#method | Returns the string method name for the request: |
#path | Returns the string path for the request: |
#request_body_permitted? | Returns whether the request may have a body: |
#response_body_permitted? | Returns whether the response may have a body: |
#uri | Returns the |
#body_exist? |
HTTPHeader
- Included
#chunked? | Returns |
#connection_close? | Returns whether the |
#connection_keep_alive? | Returns whether the |
#content_length | Returns the value of field |
#content_length= | Sets the value of field |
Instance Method Summary
HTTPGenericRequest
- Inherited
#encode_multipart_form_data, #flush_buffer, | |
#inspect | Returns a string representation of the request: |
#quote_string, #send_request_with_body, #send_request_with_body_data, #send_request_with_body_stream, #supply_default_content_type, | |
#wait_for_continue | Waits up to the continue timeout for a response from the server provided we’re speaking |
#write_header, | |
#[]= | Don’t automatically decode response content-encoding if the user indicates they want to handle it. |
#exec | write. |
#set_body_internal | internal use only. |
#update_uri | internal use only. |
HTTPHeader
- Included
#[] | Returns the string field value for the case-insensitive field |
#[]= | Sets the value for the case-insensitive |
#add_field | Adds value |
#basic_auth | Sets header |
#canonical_each | Alias for HTTPHeader#each_capitalized. |
#content_range | Returns a Range object representing the value of field |
#content_type | Returns the media type from the value of field |
#content_type= | Alias for HTTPHeader#set_content_type. |
#delete | Removes the header for the given case-insensitive |
#each | Alias for HTTPHeader#each_header. |
#each_capitalized | Like |
#each_capitalized_name | Calls the block with each capitalized field name: |
#each_header | Calls the block with each key/value pair: |
#each_key | Alias for HTTPHeader#each_name. |
#each_name | Calls the block with each field key: |
#each_value | Calls the block with each string field value: |
#fetch | With a block, returns the string value for |
#form_data= | Alias for HTTPHeader#set_form_data. |
#get_fields | Returns the array field value for the given |
#key? | Returns |
#main_type | Returns the leading (‘type’) part of the media type from the value of field |
#proxy_basic_auth | Sets header |
#range | Returns an array of Range objects that represent the value of field |
#range= | Alias for HTTPHeader#set_range. |
#range_length | Returns the integer representing length of the value of field |
#set_content_type | Sets the value of field |
#set_form | Stores form data to be used in a |
#set_form_data | Sets the request body to a URL-encoded string derived from argument |
#set_range | Sets the value for field |
#sub_type | Returns the trailing (‘subtype’) part of the media type from the value of field |
#to_hash | Returns a hash of the key/value pairs: |
#type_params | Returns the trailing (‘parameters’) part of the value of field |
#append_field_value, #basic_encode, #capitalize, #set_field, #initialize_http_header, | |
#length | Alias for HTTPHeader#size. |
#size | obsolete. |