@@ -1592,45 +1592,38 @@ def edit_path(path)
15921592
15931593 public
15941594
1595- # Retrieves data from +path+ on the connected-to host which may be an
1596- # absolute path String or a URI to extract the path from.
1597- #
1598- # +initheader+ must be a Hash like { 'Accept' => '*/*', ... },
1599- # and it defaults to an empty hash.
1600- # If +initheader+ doesn't have the key 'accept-encoding', then
1601- # a value of "gzip;q=1.0,deflate;q=0.6,identity;q=0.3" is used,
1602- # so that gzip compression is used in preference to deflate
1603- # compression, which is used in preference to no compression.
1604- # Ruby doesn't have libraries to support the compress (Lempel-Ziv)
1605- # compression, so that is not supported. The intent of this is
1606- # to reduce bandwidth by default. If this routine sets up
1607- # compression, then it does the decompression also, removing
1608- # the header as well to prevent confusion. Otherwise
1609- # it leaves the body as it found it.
1595+ # :call-seq:
1596+ # get(path, initheader = nil) {|res| ... }
16101597 #
1611- # This method returns a Net::HTTPResponse object.
1598+ # Sends a GET request to the server;
1599+ # returns a Net::HTTPResponse object,
1600+ # which actually will be an instance of a subclass of that class:
16121601 #
1613- # If called with a block, yields each fragment of the
1614- # entity body in turn as a string as it is read from
1615- # the socket. Note that in this case, the returned response
1616- # object will *not* contain a (meaningful) body.
1602+ # The request is based on the Net::HTTP::Get object
1603+ # created from string +path+ and initial headers hash +initheader+.
16171604 #
1618- # +dest+ argument is obsolete.
1619- # It still works but you must not use it.
1605+ # With a block given, calls the block with the response body:
16201606 #
1621- # This method never raises an exception.
1607+ # http.get('/todos/1') do |res|
1608+ # p res
1609+ # end # => #<Net::HTTPOK 200 OK readbody=true>
16221610 #
1623- # response = http.get('/index.html')
1611+ # Output:
16241612 #
1625- # # using block
1626- # File.open('result.txt', 'w') {|f|
1627- # http.get('/~foo/') do |str|
1628- # f.write str
1629- # end
1630- # }
1613+ # "{\n \"userId\": 1,\n \"id\": 1,\n \"title\": \"delectus aut autem\",\n \"completed\": false\n}"
1614+ #
1615+ # With no block given, simply returns the response object:
1616+ #
1617+ # http.get('/') # => #<Net::HTTPOK 200 OK readbody=true>
1618+ #
1619+ # Related:
1620+ #
1621+ # - Net::HTTP::Get: request class for \HTTP method GET.
1622+ # - Net::HTTP.get: sends GET request, returns response body.
16311623 #
16321624 def get ( path , initheader = nil , dest = nil , &block ) # :yield: +body_segment+
16331625 res = nil
1626+
16341627 request ( Get . new ( path , initheader ) ) { |r |
16351628 r . read_body dest , &block
16361629 res = r
0 commit comments