title: How To Consume Stream HTTP Response In Java?
body: <p>I'm having trouble trying to consume the Response of an HTTP Endpoint which Streams real-time events continously. It's actually one of Docker's endpoints: <a href="https://docs.docker.com/engine/api/v1.40/#operation/SystemEvents" rel="nofollow noreferrer">https://docs.docker.com/engine/api/v1.40/#operation/SystemEvents</a></p>
  
  <p>I am using Apache HTTP Client 4.5.5 and it just halts indefinitely when I try to consume the content InputStream:</p>
  
  <pre><code>HttpEntity entity = resp.getEntity();
  EntityUtils.consume(entity);//it just hangs here.
  //Even if I don't call this method, Apache calls it automatically
  //after running all my ResponseHandlers
  </code></pre>
  
  <p>Apparently, it can be done by using JDK's raw <code>URL</code>: <a href="https://stackoverflow.com/questions/11710683/stream-a-http-response-in-java">Stream a HTTP response in Java</a></p>
  
  <p>But I cannot do that since local Docker communicates over a Unix Socket which I only managed to configure in Apache's HTTP Client with a 3rd party library for Unix Sockets in Java.</p>
  
  <p>If there is a smarter HTTP Client library which I could switch to, that would also be an option.</p>
  
  <p>Any ideas would be greatly appreciated. Thank you!</p>