ruby/lib/net/http/request.rb
nagachika 359653658e merge revision(s) 8d04260acd8b6fba98867acc1a7e786495813fa0,2fbd8dca18a102cb3ffc5e7e6235c09fd0d04ba3,4165ec91d87ff1fcb41e312d896bea8a678c9bab,4d21134f3f1645ae2042d836e750ad267ee1551f,70da92cdf7ac75e071353c4551419ad02c284497,ea321a654d4b4fd6d56a1cdd6e117c62075898ee,ae68a8df586e9f3b3211e9c174b7001e57ee6aee,af67ced3b0945e8ea67434f8e66ef1e602656438,e77c766b7ab17e801c5cfa881754c392f8c13f0b:
[ruby/net-http] turn on frozen strings for net/http/header

	https://github.com/ruby/net-http/commit/a5203c9f92
	---
	 lib/net/http/header.rb | 2 +-
	 1 file changed, 1 insertion(+), 1 deletion(-)

	[ruby/net-http] turn on frozen strings for net/http/generic_request

	https://github.com/ruby/net-http/commit/b92ade088d
	---
	 lib/net/http/generic_request.rb | 6 +++---
	 1 file changed, 3 insertions(+), 3 deletions(-)

	[ruby/net-http] update net/http/response to be frozen string literal

	https://github.com/ruby/net-http/commit/dc3b4a75ca
	---
	 lib/net/http/response.rb | 6 +++---
	 1 file changed, 3 insertions(+), 3 deletions(-)

	[ruby/net-http] freeze rest of lib

	https://github.com/ruby/net-http/commit/455a74734a
	---
	 lib/net/http.rb             | 2 +-
	 lib/net/http/backward.rb    | 2 +-
	 lib/net/http/exceptions.rb  | 2 +-
	 lib/net/http/proxy_delta.rb | 2 +-
	 lib/net/http/request.rb     | 2 +-
	 lib/net/http/requests.rb    | 2 +-
	 lib/net/https.rb            | 2 +-
	 7 files changed, 7 insertions(+), 7 deletions(-)

	[ruby/net-http] Fix on 2.7

	https://github.com/ruby/net-http/commit/5194fd541e
	---
	 lib/net/http.rb | 2 +-
	 1 file changed, 1 insertion(+), 1 deletion(-)

	[ruby/net-http] use +'' everywhere

	https://github.com/ruby/net-http/commit/1077427152
	---
	 lib/net/http/generic_request.rb | 4 ++--
	 lib/net/http/response.rb        | 2 +-
	 2 files changed, 3 insertions(+), 3 deletions(-)

	[ruby/net-http] Update lib/net/http/response.rb

	@natematykiewicz's suggestion to avoid a string allocation

	https://github.com/ruby/net-http/commit/925630f227

	Co-authored-by: Nate Matykiewicz <natematykiewicz@gmail.com>
	---
	 lib/net/http/response.rb | 2 +-
	 1 file changed, 1 insertion(+), 1 deletion(-)

	[ruby/net-http] Update lib/net/http.rb

	@natematykiewicz's suggestion to avoid another string allocation

	https://github.com/ruby/net-http/commit/4a22c42338

	Co-authored-by: Nate Matykiewicz <natematykiewicz@gmail.com>
	---
	 lib/net/http.rb | 4 ++--
	 1 file changed, 2 insertions(+), 2 deletions(-)

	[ruby/net-http] No longer neccessary to call `String#freeze` on
	 string literals.

	See #144

	https://github.com/ruby/net-http/commit/5a986c13d3
	---
	 lib/net/http.rb                 | 2 +-
	 lib/net/http/generic_request.rb | 8 ++++----
	 2 files changed, 5 insertions(+), 5 deletions(-)
2023-12-16 10:48:39 +09:00

89 lines
2.8 KiB
Ruby

# frozen_string_literal: true
# This class is the base class for \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 URI or a string hostname:
#
# require 'net/http'
# uri = URI('https://jsonplaceholder.typicode.com/')
# req = Net::HTTP::Get.new(uri) # => #<Net::HTTP::Get GET>
# req = Net::HTTP::Get.new(uri.hostname) # => #<Net::HTTP::Get GET>
#
# And with any of the subclasses:
#
# req = Net::HTTP::Head.new(uri) # => #<Net::HTTP::Head HEAD>
# req = Net::HTTP::Post.new(uri) # => #<Net::HTTP::Post POST>
# req = Net::HTTP::Put.new(uri) # => #<Net::HTTP::Put PUT>
# # ...
#
# The new instance is suitable for use as the argument to Net::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:
#
# - {Request header Accept-Encoding}[https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Accept-Encoding]
# and {Compression and Decompression}[rdoc-ref:Net::HTTP@Compression+and+Decompression].
# - {Request header Accept}[https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#accept-request-header].
# - {Request header User-Agent}[https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#user-agent-request-header].
# - {Request header Host}[https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#host-request-header].
#
# You can add headers or override default headers:
#
# # res = Net::HTTP::Get.new(uri, {'foo' => '0', 'bar' => '1'})
#
# This class (and therefore its subclasses) also includes (indirectly)
# module Net::HTTPHeader, which gives access to its
# {methods for setting headers}[rdoc-ref:Net::HTTPHeader@Setters].
#
# == Request Subclasses
#
# Subclasses for HTTP requests:
#
# - Net::HTTP::Get
# - Net::HTTP::Head
# - Net::HTTP::Post
# - Net::HTTP::Put
# - Net::HTTP::Delete
# - Net::HTTP::Options
# - Net::HTTP::Trace
# - Net::HTTP::Patch
#
# Subclasses for WebDAV requests:
#
# - Net::HTTP::Propfind
# - Net::HTTP::Proppatch
# - Net::HTTP::Mkcol
# - Net::HTTP::Copy
# - Net::HTTP::Move
# - Net::HTTP::Lock
# - Net::HTTP::Unlock
#
class Net::HTTPRequest < Net::HTTPGenericRequest
# Creates an HTTP request object for +path+.
#
# +initheader+ are the default headers to use. Net::HTTP adds
# Accept-Encoding to enable compression of the response body unless
# Accept-Encoding or Range are supplied in +initheader+.
def initialize(path, initheader = nil)
super self.class::METHOD,
self.class::REQUEST_HAS_BODY,
self.class::RESPONSE_HAS_BODY,
path, initheader
end
end