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

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

https://github.com/ruby/net-http/commit/aaf26b21d6
This commit is contained in:
Burdette Lamar 2023-02-22 07:58:31 -06:00 committed by git
parent b112ae9971
commit 4edb2a29f6

View File

@ -1847,30 +1847,27 @@ module Net #:nodoc:
request(Trace.new(path, initheader)) request(Trace.new(path, initheader))
end end
# Sends a GET request to the +path+. # Sends a GET request to the server;
# Returns the response as a Net::HTTPResponse object. # forms the response into a Net::HTTPResponse object.
# #
# When called with a block, passes an HTTPResponse object to the block. # The request is based on the Net::HTTP::Get object
# The body of the response will not have been read yet; # created from string +path+ and initial headers hash +initheader+.
# the block can process it using HTTPResponse#read_body,
# if desired.
# #
# Returns the response. # With no block given, returns the response object:
# #
# This method never raises Net::* exceptions. # http = Net::HTTP.new(hostname)
# http.request_get('/todos') # => #<Net::HTTPOK 200 OK readbody=true>
# #
# response = http.request_get('/index.html') # With a block given, calls the block with the response object
# # The entity body is already read in this case. # and returns the response object:
# p response['content-type']
# puts response.body
# #
# # Using a block # http.request_get('/todos') do |res|
# http.request_get('/index.html') {|response| # p res
# p response['content-type'] # end # => #<Net::HTTPOK 200 OK readbody=true>
# response.read_body do |str| # read body now #
# print str # Output:
# end #
# } # #<Net::HTTPOK 200 OK readbody=false>
# #
def request_get(path, initheader = nil, &block) # :yield: +response+ def request_get(path, initheader = nil, &block) # :yield: +response+
request(Get.new(path, initheader), &block) request(Get.new(path, initheader), &block)