Fix chunk and content-length encoding #759
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I used the 0.13-release branch because we're updating an existing application to Visual Studio 2017 and it would build, and build against the latest boost 1.64.
At first, things didn't work at all. After using the simple_wget sample to debug it, I found that a bunch of the content (starting with the headers) had been appended after the BODY. I narrowed it down and fixed the new EOF callback when the server has sent a content-length header.
Next, Visual Studio's iterator debugging found the problem with the "len + 2" statement where it could go beyond the end of the string if the buffer didn't yet contain the crlf terminator after the current chunk. After fixing that, things mostly worked but I encountered an occasional infinite loop. From that state I figured out that the existing logic couldn't handle having a partial chunk in the buffer when checking if the chunks have all been received.
The new chunk handling code isn't overly efficient, but my changes got it to work reliably without any major changes to the partial buffer handling.