Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ce9b596

Browse files
committed
Fix closes Issue12315 - Updates to http.client documentation.
1 parent 206cd1c commit ce9b596

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

Doc/library/http.client.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,9 @@ statement.
543543
A debugging hook. If :attr:`debuglevel` is greater than zero, messages
544544
will be printed to stdout as the response is read and parsed.
545545

546+
.. attribute:: HTTPResponse.closed
547+
548+
Is True if the stream is closed.
546549

547550
Examples
548551
--------
@@ -555,7 +558,15 @@ Here is an example session that uses the ``GET`` method::
555558
>>> r1 = conn.getresponse()
556559
>>> print(r1.status, r1.reason)
557560
200 OK
558-
>>> data1 = r1.read()
561+
>>> data1 = r1.read() # This will return entire content.
562+
>>> # The following example demonstrates reading data in chunks.
563+
>>> conn.request("GET", "/index.html")
564+
>>> r1 = conn.getresponse()
565+
>>> while not r1.closed:
566+
... print(r1.read(200)) # 200 bytes
567+
b'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
568+
...
569+
>>> # Example of an invalid request
559570
>>> conn.request("GET", "/parrot.spam")
560571
>>> r2 = conn.getresponse()
561572
>>> print(r2.status, r2.reason)

0 commit comments

Comments
 (0)