diff options
author | Burdette Lamar <[email protected]> | 2023-02-22 07:58:31 -0600 |
---|---|---|
committer | git <[email protected]> | 2023-02-22 13:58:36 +0000 |
commit | 4edb2a29f67957fc7027eaad0c08e8003cfde609 (patch) | |
tree | 132306ea8d830f2764c5fe5e4ed3f17975c8465f /lib/net/http.rb | |
parent | b112ae9971ea63b9f0ba3df049ac4c3bea89bf66 (diff) |
[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
Diffstat (limited to 'lib/net/http.rb')
-rw-r--r-- | lib/net/http.rb | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/lib/net/http.rb b/lib/net/http.rb index e39ab0b629..7a3272d2ce 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -1847,30 +1847,27 @@ module Net #:nodoc: request(Trace.new(path, initheader)) end - # Sends a GET request to the +path+. - # Returns the response as a Net::HTTPResponse object. + # Sends a GET request to the server; + # forms the response into a Net::HTTPResponse object. # - # When called with a block, passes an HTTPResponse object to the block. - # The body of the response will not have been read yet; - # the block can process it using HTTPResponse#read_body, - # if desired. + # The request is based on the Net::HTTP::Get object + # created from string +path+ and initial headers hash +initheader+. # - # 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') - # # The entity body is already read in this case. - # p response['content-type'] - # puts response.body + # With a block given, calls the block with the response object + # and returns the response object: # - # # Using a block - # http.request_get('/index.html') {|response| - # p response['content-type'] - # response.read_body do |str| # read body now - # print str - # end - # } + # http.request_get('/todos') do |res| + # p res + # end # => #<Net::HTTPOK 200 OK readbody=true> + # + # Output: + # + # #<Net::HTTPOK 200 OK readbody=false> # def request_get(path, initheader = nil, &block) # :yield: +response+ request(Get.new(path, initheader), &block) |