nmattisson / HttpClient

Http Client Library for the Spark Core (also well suited for Arduino and other embedded platforms).
Other
121 stars 150 forks source link

Implemented chunked read, when not all the data is ready at first read #3

Closed synox closed 10 years ago

synox commented 10 years ago

Hi

I have problems with websites that deliver parts of the response after a delay. I created a php-script (https://gist.github.com/synox/d8fc60b1d9abfd75005e) to test this behaviour.

I fixed the issue by using the alogrithm from:

https://community.spark.io/t/tcp-client-not-reading-anything/2427/20

in the end, it does not take the first value from client.available(), but waits for more data to arrive. Remeber that client.available() only returns the bytes currently in the buffer, but there might be more bytes coming.

i uploaded the php-script here: http://dubgo.com/tmp/timing.php

how to reproduce

use your example application.cpp, and replace the request lines with: request.hostname = "www.dubgo.com"; request.port = 80; request.path = "/tmp/timing.php";

nmattisson commented 10 years ago

Looks good, I'll merge it and then make some minor changes for style etc. Thank you!

nmattisson commented 10 years ago

I removed the nested while loops since I thought it a bit hard to read, and added more explicit names for the conditions (error and timeout). The functionality should be the same, and the changes are quite minor. Let me know what you think!

Thanks again for helping out. :)

synox commented 10 years ago

looks good, I think you should put a break; at Line 187: https://github.com/nmattisson/HttpClient/blob/master/HttpClient.cpp#L187

nmattisson commented 10 years ago

Yes, thank you for spotting the mistake. I fixed it in https://github.com/nmattisson/HttpClient/commit/603e83918d0500fd6df13acecdfeefc02878d776.

On Mar 31, 2014, at 5:58 PM, synox notifications@github.com wrote:

looks good, I think you should put a break; at Line 187: https://github.com/nmattisson/HttpClient/blob/master/HttpClient.cpp#L187

— Reply to this email directly or view it on GitHub.