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

A small bugfix and a change in behaviour (which should be transparent to the user). #30

Closed Undergrid closed 8 years ago

Undergrid commented 8 years ago

First there was a condition whereby a NULL would be written outside of the buffer when the buffer had previously reached capacity. This would overwrite the first byte of whatever variable happened to be declared after the HttpClient object. Setting the NULL was not required since the buffer was entirely zeroed before starting to copy the stream into it and a terminating NULL was already added when the buffer had been filled. I've removed adding the NULL.

Second, I've modified when the detection of the headers and body are done. Rather than the previous method, we now look for two "\n" characters in a row (ignoring any intervening "\r"'s) as the stream is being received. When detected, we extract the status code and zero the buffer (we could save the headers at this point, but we were just throwing them away anyway), which allows the entire size of the buffer to receive body content without using additional memory. We also avoid copying the buffer into a String at a later point to facilitate splitting, thus saving memory.

nmattisson commented 8 years ago

Awesome, thanks!