title: Read octet stream in C Program
body: <p>I would like to read an octet-stream in my C code. Example of output (it's docker API log output):</p>
  
  <pre><code>HTTP/1.0 200 OK
  Date: Wed, 13 May 2015 20:09:13 GMT
  Content-Type: application/octet-stream
  
  ▒2015-05-13T20:09:06.335126685Z 2015-05-13 20:09:06 ERROR AppException: &lt;traceback&gt;
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>char *message = NULL;
  char buffer[buffer_size+1];
  while ((nbytes = read(sock, buffer, buffer_size)) &gt; 0 )
  {
      buffer[nbytes] = 0;
      message = realloc(message, (strlen(message) + nbytes + 1));
      strcat(message, buffer);
  }
  log(LOG_LEVEL_DEBUG, "message: %s", message);
  </code></pre>
  
  <p>But I'm able to read only headers (debug output of message variable):</p>
  
  <pre><code>▒w▒WHTTP/1.0 200 OK
  Date: Wed, 13 May 2015 20:14:41 GMT
  Content-Type: application/octet-stream
  </code></pre>
  
  <p>How can I read content of response? 
  Can the non-ASCII character in response be a problem? 
  Another Docker API responses (inspect, info, ps) doesn't have this issue.</p>