title: Tornado IOStream.read_until_close does not work properly
body: <h2>Code</h2>
  
  <p>Use Tornado IOStream.read_until_close for reading http response.</p>
  
  <pre><code>from tornado import ioloop
  from tornado import iostream
  import socket    
  
  class Client(object):
      def __init__(self, domen, uri):
          self.uri = uri
          self.domen = domen
  
          s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
          self.stream = iostream.IOStream(s)
  
      def open(self):
          self.stream.connect((self.domen, 80), self.send_request)
  
      def on_chunk_read(self, chunk):
          print "chunk\n", chunk
  
      def on_close(self, res):
          print "res\n", res
          self.stream.close()
          ioloop.IOLoop.instance().stop()
  
      def send_request(self):
          self.stream.write(
              "GET %s HTTP/1.0\r\nHost: %s\r\n\r\n" % (self.uri,  self.domen))
          self.stream.read_until_close(self.on_close, self.on_chunk_read)
  
  client = Client("www.google.com", "/")
  client.open()
  
  ioloop.IOLoop.instance().start()
  </code></pre>
  
  <h2>Output</h2>
  
  <pre><code>res
  HTTP/1.0 302 Found
  Location: http://www.google.ru/
  ...
  &lt;HTML&gt;
  ...
  &lt;/HTML&gt;
  </code></pre>
  
  <h2>Documentation <a href="http://www.tornadoweb.org/documentation/iostream.html#tornado.iostream.IOStream.read_until_close" rel="nofollow">tornado.iostream</a></h2>
  
  <pre><code>read_until_close(callback, streaming_callback=None)
  Reads all data from the socket until it is closed.
  
  If a streaming_callback is given, it will be called with chunks of data as they 
  become  available, and the argument to the final callback will be empty.
  
  Subject to max_buffer_size limit from IOStream constructor if a 
  streaming_callback is not used.
  </code></pre>
  
  <h2>Сonclusion</h2>
  
  <p>Code 'print "chunk\n", chunk' not called.
  Called callback, but streaming_callback not called.</p>
  
  <p>It is bug?</p>