File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
547550Examples
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)
You can’t perform that action at this time.
0 commit comments