From af7b5301cd99e97dbc994e17e526ad3d914b9a41 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Tue, 14 Feb 2023 20:56:11 +0000 Subject: [PATCH 1/2] Enhanced RDoc for Net::HTTP#get --- lib/net/http.rb | 48 ++++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/lib/net/http.rb b/lib/net/http.rb index 15fc348b..84878a08 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -1592,45 +1592,33 @@ def edit_path(path) public - # Retrieves data from +path+ on the connected-to host which may be an - # absolute path String or a URI to extract the path from. - # - # +initheader+ must be a Hash like { 'Accept' => '*/*', ... }, - # and it defaults to an empty hash. - # If +initheader+ doesn't have the key 'accept-encoding', then - # a value of "gzip;q=1.0,deflate;q=0.6,identity;q=0.3" is used, - # so that gzip compression is used in preference to deflate - # compression, which is used in preference to no compression. - # Ruby doesn't have libraries to support the compress (Lempel-Ziv) - # compression, so that is not supported. The intent of this is - # to reduce bandwidth by default. If this routine sets up - # compression, then it does the decompression also, removing - # the header as well to prevent confusion. Otherwise - # it leaves the body as it found it. + # :call-seq: + # get(path, initheader = nil) {|res| ... } # - # This method returns a Net::HTTPResponse object. + # Sends a GET request to the server. + # The request is based on the Net::HTTP::Get object + # created from string +path+ and initial headers hash +initheader+. # - # If called with a block, yields each fragment of the - # entity body in turn as a string as it is read from - # the socket. Note that in this case, the returned response - # object will *not* contain a (meaningful) body. + # With a block given, returns a Net::HTTPResponse object, + # which actually will be an instance of a subclass of that class: # - # +dest+ argument is obsolete. - # It still works but you must not use it. + # http = Net::HTTP.new(hostname) + # http.get('/') do |res| + # res + # end # => # # - # This method never raises an exception. + # With no block given, returns the response object: # - # response = http.get('/index.html') + # http.get('/') # => # # - # # using block - # File.open('result.txt', 'w') {|f| - # http.get('/~foo/') do |str| - # f.write str - # end - # } + # Related: + # + # - Net::HTTP::Get: request class for \HTTP method GET. + # - Net::HTTP.get: sends GET request, returns response body. # def get(path, initheader = nil, dest = nil, &block) # :yield: +body_segment+ res = nil + request(Get.new(path, initheader)) {|r| r.read_body dest, &block res = r From 3b9692fcf3c71717d0d43624efcf079f4e43c143 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Tue, 14 Feb 2023 22:24:19 +0000 Subject: [PATCH 2/2] Enhanced RDoc for Net::HTTP#get --- lib/net/http.rb | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/net/http.rb b/lib/net/http.rb index 84878a08..d8d8c932 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -1595,19 +1595,24 @@ def edit_path(path) # :call-seq: # get(path, initheader = nil) {|res| ... } # - # Sends a GET request to the server. + # Sends a GET request to the server; + # returns a Net::HTTPResponse object, + # which actually will be an instance of a subclass of that class: + # # The request is based on the Net::HTTP::Get object # created from string +path+ and initial headers hash +initheader+. # - # With a block given, returns a Net::HTTPResponse object, - # which actually will be an instance of a subclass of that class: + # With a block given, calls the block with the response body: # - # http = Net::HTTP.new(hostname) - # http.get('/') do |res| - # res + # http.get('/todos/1') do |res| + # p res # end # => # # - # With no block given, returns the response object: + # Output: + # + # "{\n \"userId\": 1,\n \"id\": 1,\n \"title\": \"delectus aut autem\",\n \"completed\": false\n}" + # + # With no block given, simply returns the response object: # # http.get('/') # => # #