[ruby/net-http] [DOC] Enhanced RDoc for Net::HTTP

(https://github.com/ruby/net-http/pull/84)

https://github.com/ruby/net-http/commit/660046386f
This commit is contained in:
Burdette Lamar 2022-12-04 14:22:25 -06:00 committed by git
parent dba61f487c
commit e58c4f97fa
2 changed files with 318 additions and 42 deletions

View File

@ -4,23 +4,28 @@
# it wraps together the request path and the request headers.
#
# The class should not be used directly;
# instead you should use its subclasses:
# instead you should use its subclasses.
#
# - \Net::HTTP::Get
# - \Net::HTTP::Head
# - \Net::HTTP::Post
# - \Net::HTTP::Delete
# - \Net::HTTP::Options
# - \Net::HTTP::Trace
# - \Net::HTTP::Patch
# - \Net::HTTP::Put
# - \Net::HTTP::Copy
# - \Net::HTTP::Lock
# - \Net::HTTP::Mkcol
# - \Net::HTTP::Move
# - \Net::HTTP::Propfind
# - \Net::HTTP::Proppatch
# - \Net::HTTP::Unlock
# 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+.
@ -36,4 +41,3 @@ class Net::HTTPRequest < Net::HTTPGenericRequest
path, initheader
end
end

View File

@ -1,67 +1,241 @@
# frozen_string_literal: false
#
# HTTP/1.1 methods --- RFC2616
#
# See Net::HTTPGenericRequest for attributes and methods.
# See Net::HTTP for usage examples.
# HTTP/1.1 methods --- RFC2616
# \Class for representing
# {HTTP method GET}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#GET_method]:
#
# require 'net/http'
# uri = URI('http://example.com')
# hostname = uri.hostname # => "example.com"
# req = Net::HTTP::Get.new(uri) # => #<Net::HTTP::Get GET>
# res = Net::HTTP.start(hostname) do |http|
# http.request(req)
# end
#
# Properties:
#
# - Request body: optional.
# - Response body: yes.
# - {Safe}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Safe_methods]: yes.
# - {Idempotent}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Idempotent_methods]: yes.
# - {Cacheable}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Cacheable_methods]: yes.
#
# Related:
#
# - Net::HTTP.get: sends +GET+ request, returns response body.
# - Net::HTTP#get: sends +GET+ request, returns response object.
#
class Net::HTTP::Get < Net::HTTPRequest
METHOD = 'GET'
REQUEST_HAS_BODY = false
RESPONSE_HAS_BODY = true
end
# See Net::HTTPGenericRequest for attributes and methods.
# See Net::HTTP for usage examples.
# \Class for representing
# {HTTP method HEAD}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#HEAD_method]:
#
# require 'net/http'
# uri = URI('http://example.com')
# hostname = uri.hostname # => "example.com"
# req = Net::HTTP::Head.new(uri) # => #<Net::HTTP::Head HEAD>
# res = Net::HTTP.start(hostname) do |http|
# http.request(req)
# end
#
# Properties:
#
# - Request body: optional.
# - Response body: no.
# - {Safe}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Safe_methods]: yes.
# - {Idempotent}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Idempotent_methods]: yes.
# - {Cacheable}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Cacheable_methods]: yes.
#
# Related:
#
# - Net::HTTP#head: sends +HEAD+ request, returns response object.
#
class Net::HTTP::Head < Net::HTTPRequest
METHOD = 'HEAD'
REQUEST_HAS_BODY = false
RESPONSE_HAS_BODY = false
end
# See Net::HTTPGenericRequest for attributes and methods.
# See Net::HTTP for usage examples.
# \Class for representing
# {HTTP method POST}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#POST_method]:
#
# require 'net/http'
# uri = URI('http://example.com')
# hostname = uri.hostname # => "example.com"
# uri.path = '/posts'
# req = Net::HTTP::Post.new(uri) # => #<Net::HTTP::Post POST>
# req.body = '{"title": "foo","body": "bar","userId": 1}'
# req.content_type = 'application/json'
# res = Net::HTTP.start(hostname) do |http|
# http.request(req)
# end
#
# Properties:
#
# - Request body: yes.
# - Response body: yes.
# - {Safe}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Safe_methods]: no.
# - {Idempotent}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Idempotent_methods]: no.
# - {Cacheable}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Cacheable_methods]: yes.
#
# Related:
#
# - Net::HTTP.post: sends +POST+ request, returns response object.
# - Net::HTTP#post: sends +POST+ request, returns response object.
#
class Net::HTTP::Post < Net::HTTPRequest
METHOD = 'POST'
REQUEST_HAS_BODY = true
RESPONSE_HAS_BODY = true
end
# See Net::HTTPGenericRequest for attributes and methods.
# See Net::HTTP for usage examples.
# \Class for representing
# {HTTP method PUT}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#PUT_method]:
#
# require 'net/http'
# uri = URI('http://example.com')
# hostname = uri.hostname # => "example.com"
# uri.path = '/posts'
# req = Net::HTTP::Put.new(uri) # => #<Net::HTTP::Put PUT>
# req.body = '{"title": "foo","body": "bar","userId": 1}'
# req.content_type = 'application/json'
# res = Net::HTTP.start(hostname) do |http|
# http.request(req)
# end
#
# Properties:
#
# - Request body: yes.
# - Response body: yes.
# - {Safe}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Safe_methods]: no.
# - {Idempotent}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Idempotent_methods]: yes.
# - {Cacheable}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Cacheable_methods]: no.
#
class Net::HTTP::Put < Net::HTTPRequest
METHOD = 'PUT'
REQUEST_HAS_BODY = true
RESPONSE_HAS_BODY = true
end
# See Net::HTTPGenericRequest for attributes and methods.
# See Net::HTTP for usage examples.
# \Class for representing
# {HTTP method DELETE}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#DELETE_method]:
#
# require 'net/http'
# uri = URI('http://example.com')
# hostname = uri.hostname # => "example.com"
# uri.path = '/posts/1'
# req = Net::HTTP::Delete.new(uri) # => #<Net::HTTP::Delete DELETE>
# res = Net::HTTP.start(hostname) do |http|
# http.request(req)
# end
#
# Properties:
#
# - Request body: optional.
# - Response body: yes.
# - {Safe}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Safe_methods]: no.
# - {Idempotent}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Idempotent_methods]: yes.
# - {Cacheable}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Cacheable_methods]: no.
#
# Related:
#
# - Net::HTTP#delete: sends +DELETE+ request, returns response object.
#
class Net::HTTP::Delete < Net::HTTPRequest
METHOD = 'DELETE'
REQUEST_HAS_BODY = false
RESPONSE_HAS_BODY = true
end
# See Net::HTTPGenericRequest for attributes and methods.
# \Class for representing
# {HTTP method OPTIONS}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#OPTIONS_method]:
#
# require 'net/http'
# uri = URI('http://example.com')
# hostname = uri.hostname # => "example.com"
# req = Net::HTTP::Options.new(uri) # => #<Net::HTTP::Options OPTIONS>
# res = Net::HTTP.start(hostname) do |http|
# http.request(req)
# end
#
# Properties:
#
# - Request body: optional.
# - Response body: yes.
# - {Safe}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Safe_methods]: yes.
# - {Idempotent}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Idempotent_methods]: yes.
# - {Cacheable}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Cacheable_methods]: no.
#
# Related:
#
# - Net::HTTP#options: sends +OPTIONS+ request, returns response object.
#
class Net::HTTP::Options < Net::HTTPRequest
METHOD = 'OPTIONS'
REQUEST_HAS_BODY = false
RESPONSE_HAS_BODY = true
end
# See Net::HTTPGenericRequest for attributes and methods.
# \Class for representing
# {HTTP method TRACE}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#TRACE_method]:
#
# require 'net/http'
# uri = URI('http://example.com')
# hostname = uri.hostname # => "example.com"
# req = Net::HTTP::Trace.new(uri) # => #<Net::HTTP::Trace TRACE>
# res = Net::HTTP.start(hostname) do |http|
# http.request(req)
# end
#
# Properties:
#
# - Request body: no.
# - Response body: yes.
# - {Safe}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Safe_methods]: yes.
# - {Idempotent}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Idempotent_methods]: yes.
# - {Cacheable}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Cacheable_methods]: no.
#
# Related:
#
# - Net::HTTP#trace: sends +TRACE+ request, returns response object.
#
class Net::HTTP::Trace < Net::HTTPRequest
METHOD = 'TRACE'
REQUEST_HAS_BODY = false
RESPONSE_HAS_BODY = true
end
# \Class for representing
# {HTTP method PATCH}[https://en.wikipedia.org/w/index.php?title=Hypertext_Transfer_Protocol#PATCH_method]:
#
# PATCH method --- RFC5789
# require 'net/http'
# uri = URI('http://example.com')
# hostname = uri.hostname # => "example.com"
# uri.path = '/posts'
# req = Net::HTTP::Patch.new(uri) # => #<Net::HTTP::Patch PATCH>
# req.body = '{"title": "foo","body": "bar","userId": 1}'
# req.content_type = 'application/json'
# res = Net::HTTP.start(hostname) do |http|
# http.request(req)
# end
#
# Properties:
#
# - Request body: yes.
# - Response body: yes.
# - {Safe}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Safe_methods]: no.
# - {Idempotent}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Idempotent_methods]: no.
# - {Cacheable}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Cacheable_methods]: no.
#
# Related:
#
# - Net::HTTP#patch: sends +PATCH+ request, returns response object.
#
# See Net::HTTPGenericRequest for attributes and methods.
class Net::HTTP::Patch < Net::HTTPRequest
METHOD = 'PATCH'
REQUEST_HAS_BODY = true
@ -72,49 +246,147 @@ end
# WebDAV methods --- RFC2518
#
# See Net::HTTPGenericRequest for attributes and methods.
# \Class for representing
# {WebDAV method PROPFIND}[http://www.webdav.org/specs/rfc4918.html#METHOD_PROPFIND]:
#
# require 'net/http'
# uri = URI('http://example.com')
# hostname = uri.hostname # => "example.com"
# req = Net::HTTP::Propfind.new(uri) # => #<Net::HTTP::Propfind PROPFIND>
# res = Net::HTTP.start(hostname) do |http|
# http.request(req)
# end
#
# Related:
#
# - Net::HTTP#propfind: sends +PROPFIND+ request, returns response object.
#
class Net::HTTP::Propfind < Net::HTTPRequest
METHOD = 'PROPFIND'
REQUEST_HAS_BODY = true
RESPONSE_HAS_BODY = true
end
# See Net::HTTPGenericRequest for attributes and methods.
# \Class for representing
# {WebDAV method PROPPATCH}[http://www.webdav.org/specs/rfc4918.html#METHOD_PROPPATCH]:
#
# require 'net/http'
# uri = URI('http://example.com')
# hostname = uri.hostname # => "example.com"
# req = Net::HTTP::Proppatch.new(uri) # => #<Net::HTTP::Proppatch PROPPATCH>
# res = Net::HTTP.start(hostname) do |http|
# http.request(req)
# end
#
# Related:
#
# - Net::HTTP#proppatch: sends +PROPPATCH+ request, returns response object.
#
class Net::HTTP::Proppatch < Net::HTTPRequest
METHOD = 'PROPPATCH'
REQUEST_HAS_BODY = true
RESPONSE_HAS_BODY = true
end
# See Net::HTTPGenericRequest for attributes and methods.
# \Class for representing
# {WebDAV method MKCOL}[http://www.webdav.org/specs/rfc4918.html#METHOD_MKCOL]:
#
# require 'net/http'
# uri = URI('http://example.com')
# hostname = uri.hostname # => "example.com"
# req = Net::HTTP::Mkcol.new(uri) # => #<Net::HTTP::Mkcol MKCOL>
# res = Net::HTTP.start(hostname) do |http|
# http.request(req)
# end
#
# Related:
#
# - Net::HTTP#mkcol: sends +MKCOL+ request, returns response object.
#
class Net::HTTP::Mkcol < Net::HTTPRequest
METHOD = 'MKCOL'
REQUEST_HAS_BODY = true
RESPONSE_HAS_BODY = true
end
# See Net::HTTPGenericRequest for attributes and methods.
# \Class for representing
# {WebDAV method COPY}[http://www.webdav.org/specs/rfc4918.html#METHOD_COPY]:
#
# require 'net/http'
# uri = URI('http://example.com')
# hostname = uri.hostname # => "example.com"
# req = Net::HTTP::Copy.new(uri) # => #<Net::HTTP::Copy COPY>
# res = Net::HTTP.start(hostname) do |http|
# http.request(req)
# end
#
# Related:
#
# - Net::HTTP#copy: sends +COPY+ request, returns response object.
#
class Net::HTTP::Copy < Net::HTTPRequest
METHOD = 'COPY'
REQUEST_HAS_BODY = false
RESPONSE_HAS_BODY = true
end
# See Net::HTTPGenericRequest for attributes and methods.
# \Class for representing
# {WebDAV method MOVE}[http://www.webdav.org/specs/rfc4918.html#METHOD_MOVE]:
#
# require 'net/http'
# uri = URI('http://example.com')
# hostname = uri.hostname # => "example.com"
# req = Net::HTTP::Move.new(uri) # => #<Net::HTTP::Move MOVE>
# res = Net::HTTP.start(hostname) do |http|
# http.request(req)
# end
#
# Related:
#
# - Net::HTTP#move: sends +MOVE+ request, returns response object.
#
class Net::HTTP::Move < Net::HTTPRequest
METHOD = 'MOVE'
REQUEST_HAS_BODY = false
RESPONSE_HAS_BODY = true
end
# See Net::HTTPGenericRequest for attributes and methods.
# \Class for representing
# {WebDAV method LOCK}[http://www.webdav.org/specs/rfc4918.html#METHOD_LOCK]:
#
# require 'net/http'
# uri = URI('http://example.com')
# hostname = uri.hostname # => "example.com"
# req = Net::HTTP::Lock.new(uri) # => #<Net::HTTP::Lock LOCK>
# res = Net::HTTP.start(hostname) do |http|
# http.request(req)
# end
#
# Related:
#
# - Net::HTTP#lock: sends +LOCK+ request, returns response object.
#
class Net::HTTP::Lock < Net::HTTPRequest
METHOD = 'LOCK'
REQUEST_HAS_BODY = true
RESPONSE_HAS_BODY = true
end
# See Net::HTTPGenericRequest for attributes and methods.
# \Class for representing
# {WebDAV method UNLOCK}[http://www.webdav.org/specs/rfc4918.html#METHOD_UNLOCK]:
#
# require 'net/http'
# uri = URI('http://example.com')
# hostname = uri.hostname # => "example.com"
# req = Net::HTTP::Unlock.new(uri) # => #<Net::HTTP::Unlock UNLOCK>
# res = Net::HTTP.start(hostname) do |http|
# http.request(req)
# end
#
# Related:
#
# - Net::HTTP#unlock: sends +UNLOCK+ request, returns response object.
#
class Net::HTTP::Unlock < Net::HTTPRequest
METHOD = 'UNLOCK'
REQUEST_HAS_BODY = true