Hi Hugo,
Adding 302/303 to line 1542 of src/target.c is not enough - as the Transfer-Encoding: chunked header is present the content_length var is immediately reset to -1 by the following if block at 1559. However, after a bit of reading on the RFC on chunked encoding I think I have tracked down the problem to the block at line 1595:
if (chunked && (bytes_in_buffer >= 7)) {
if (memcmp(buffer + bytes_in_buffer - 7, "\r\n0\r\n\r\n", 7) == 0) {
keep_reading = false;
}
}
Change this to:
if (chunked && (bytes_in_buffer >= 5)) {
if (memcmp(buffer + bytes_in_buffer - 5, "0\r\n\r\n", 5) == 0) {
keep_reading = false;
}
}
and the problem goes away.
It appears there is no certainty of there being a CRLF in front of the 0 length final chunk - for instance when it is the first line in the buffer. If there are any other implications as a result of this change, I don't know but everything I have tested it with seems to work correctly with no delay.
Hope this helps. DJ