title: How can I read exactly one response chunk with python's http.client?
body: <p>Using <code>http.client</code> in Python 3.3+ (or any other builtin python HTTP client library), how can I read a chunked HTTP response exactly one HTTP chunk at a time?</p>
  
  <p>I'm extending an existing test fixture (written in python using <code>http.client</code>) for a server which writes its response using HTTP's chunked transfer encoding. For the sake of simplicity, let's say that I'd like to be able to print a message whenever an HTTP chunk is received by the client.</p>
  
  <p>My code follows a fairly standard pattern for reading a large response:</p>
  
  <pre><code>conn = http.client.HTTPConnection(...)
  conn.request(...)
  response = conn.getresponse()
  
  resbody = []
  
  while True:
      chunk = response.read(1024)
      if len(chunk):
          resbody.append(chunk)
      else:
          break
  
  conn.close();
  </code></pre>
  
  <p>But this reads 1024 byte chunks regardless of whether or not the server is sending 10 byte chunks or 10MiB chunks.</p>
  
  <p>What I'm looking for would be something like the following:</p>
  
  <pre><code>while True:
      chunk = response.readchunk()
      if len(chunk):
          resbody.append(chunk)
      else
          break
  </code></pre>
  
  <p>If this is not possible with <code>http.client</code>, is it possible with another builtin http client library? If it's not possible with a builtin client lib, is it possible with <code>pip</code> installable module?</p>