10 years, 3 months ago.  This question has been closed. Reason: Solved

HTTP client blocks for whole time out period

I have a simple use case for http client to fetch some text:

char str[256];
HTTPText data(str, 256);
HTTPResult r = client.get(updateurl.c_str(), &data);

The call to get took ages to return. I discovered a proportional relationship between the specified timeout and the length of time the call blocked for. It looks like the call to get blocks for the whole timeout period regardless of how long it actually took to get any data back from the server. If this is the case this then firstly this is a confusing use of the word timeout and secondly, why can't it just block until some data is received?

2 Answers

10 years, 1 month ago.

Hi David,

Thanks for the response. I think I got this working in the end (too long ago to remember precisely). I am pretty sure I had a bug the HTTP server I was using, wrong mime type or something like that. Not sure why it resulted in the client timing out, my guess is the client thought that it had not received the whole message so continued to wait until it timed out.

Anyway, thanks again.

10 years, 1 month ago.

Hi Ollie,

I only have a little experience with HTTPClient, but if I understand the code correctly, there is not a way for it to give you a chunk at a time. So, while it could be good to get the first piece, the rest would appear to go into the bit-bucket. A related item I'm going to face one of these days - For testing, the information I fetch isn't very big, so it is easy to size a buffer large enough to receive it all. But as my need grows, I'll need a way to get a chunk at a time. It might be that it supports this and I simply don't yet realize how to accomplish this.

More specific to your point - I have not noticed that behavior (of it waiting the full timeout interval), but with my need, I'm not sure I would have. I can imagine that if the get method was fully protocol aware, then it could parse the inbound data on the fly, and by examination of the header it could determine when the message transfer is complete and return early.