code: def write_to_stream(stream, response, block_len=1024):
          
          try:
              i_start = 0
              i_end = block_len
              while True:
                  if i_end > len(response):
                      stream(response[i_start:])
                      break
                  stream(response[i_start:i_end])
                  i_start = i_end
                  i_end += block_len
          except (socket.timeout, socket.error) as exception:
              logger.debug('Error sending response to the client: %s', exception)
docs: Send the response in blocks of the given len using the
          passed method dependending on the socket type.