0

Does a http client return a stream as the response or does it reads the bytes from the stream and returns us the response ?

If it returns a stream , the user will have to read from that stream to get the response right ?

For example - We are using ApacheAsyncHttpClient to get blobs from Azure Storage. The REST response should only contain the stream from where to read the blob right ? But what I observed is that the client itself is reading all the bytes from the stream before invoking our completed Callback.

And unless the data from the stream is read , the HTTP connection is kept open ?

Edit - We cant use sdk for reasons beyond the scope of this question. My question is specifically for ApacheAsyncHttpClient.

It reads the entire stream before calling the completed callback. Ideally, what I would want is that it returns me the stream and my application will read from that stream. Is there a way to do that ? And are all http clients behave similarly ?

  • 2
    That depends entirely on the client. The server will return a stream of bytes over TCP/IP. Whoever is handling the returned stream can decide what to do with it. So you probably need to read in a different way. I'm sure the documentation has all the answers. – Kayaman Apr 05 '18 at 07:49
  • As @Kayaman said, have you tried using the default sdk ?? https://github.com/Azure/azure-storage-java – Thomas Apr 05 '18 at 07:57
  • @kayaman - Edited the question – lostintranslation Apr 05 '18 at 12:04
  • Did you read the documentation and did it say anything about getting a stream result? Not all HTTP clients behave in the same way. You can write your own and make it do all sorts of crazy things. But in general they work in pretty much the same way. After all, they all perform HTTP requests and that does set some boundaries. – Kayaman Apr 05 '18 at 12:09
  • I tried to implement my own Consumer to stream response body but was not able to do it. I want to return the completableFuture of the response object to my client. He will then start reading from the stream in the response object. For reference -> https://stackoverflow.com/questions/50294297/async-response-streaming-with-apache-async-http-client – lostintranslation May 15 '18 at 14:04

0 Answers0