Skip to content

Commit 570f034

Browse files
committed
httpclient: read_body should return 0 at EOF
When users call `git_http_client_read_body`, it should return 0 at the end of a message. When the `on_message_complete` callback is called, this will set `client->state` to `DONE`. In our read loop, we look for this condition and exit. Without this, when there is no data left except the end of message chunk (`0\r\n`) in the http stream, we would block by reading the three bytes off the stream but not making progress in any `on_body` callbacks. Listening to the `on_message_complete` callback allows us to stop trying to read from the socket when we've read the end of message chunk.
1 parent b7bdb07 commit 570f034

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/transports/httpclient.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,15 +1419,20 @@ int git_http_client_read_body(
14191419
client->parser.data = &parser_context;
14201420

14211421
/*
1422-
* Clients expect to get a non-zero amount of data from us.
1423-
* With a sufficiently small buffer, one might only read a chunk
1424-
* length. Loop until we actually have data to return.
1422+
* Clients expect to get a non-zero amount of data from us,
1423+
* so we either block until we have data to return, until we
1424+
* hit EOF or there's an error. Do this in a loop, since we
1425+
* may end up reading only some stream metadata (like chunk
1426+
* information).
14251427
*/
14261428
while (!parser_context.output_written) {
14271429
error = client_read_and_parse(client);
14281430

14291431
if (error <= 0)
14301432
goto done;
1433+
1434+
if (client->state == DONE)
1435+
break;
14311436
}
14321437

14331438
assert(parser_context.output_written <= INT_MAX);

0 commit comments

Comments
 (0)