Do not report a body that ends with the connection as an error

A response with neither Content-Length nor chunked encoding ends when
the connection closes (RFC 9112 6.3), but the stream API set
read_error() to ConnectionClosed on reaching that end, and SSEClient
passed it on to on_error. Only a body shorter than its Content-Length
is cut short there.
This commit is contained in:
yhirose committed 2026-10-18 12:41:23 -04:00
1 parent 106edcf606
commit 07edfb86b4
2 files changed
+81 -8

No files matched your search

+5 -8
View File
@@ -12404,19 +12404,16 @@ inline ssize_t detail::BodyReader::read(char *buf, size_t len) {
}
auto n = stream->read(buf, to_read);
if (n < 0) {
// Without Content-Length the body ends when the connection closes
// (RFC 9112 §6.3); with one, an EOF here came too early
if (n < 0 || (n == 0 && has_content_length)) {
last_error = stream->get_error();
if (last_error == Error::Success) { last_error = Error::Read; }
}
if (n <= 0) {
eof = true;
return n;
}
if (n == 0) {
// Unexpected EOF before content_length
last_error = stream->get_error();
if (last_error == Error::Success) { last_error = Error::Read; }
eof = true;
return 0;
}
bytes_read += static_cast<size_t>(n);
if (has_content_length && bytes_read >= content_length) { eof = true; }