mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-19 11:19:36 +00:00
Do not let a zero-length write end a chunked body (#2563)
write_content_chunked()'s sink treated "the provider wrote nothing" as
"the provider has finished":
data_available = l > 0;
so sink.write(p, 0) ended the loop. Only done()/done_with_trailer()
emit the terminating zero-length chunk, so the body was left
unterminated - and the function still returned Success, because the
post-loop check only reports the is_shutting_down() case. The peer waits
for a last chunk that never arrives, and on a keep-alive connection
anything written next is parsed as a chunk-size line.
A provider reaching a pass with nothing to hand over is ordinary:
popping an empty buffer off a queue, or a compressor that has consumed
its input without producing output yet. It is not the end of the
message.
Ignore zero-length writes instead. A zero-length chunk is the terminator
in chunked coding, so it must never be emitted mid-body either way, and
data_available is now controlled only by done()/done_with_trailer().
This matches write_content_without_length(), where the sink's write
never ends the body.
The old behaviour cannot have been relied on: it produced an
unterminated response, so a provider using it never worked in the first
place.
This commit is contained in:
1 parent
bc7e51dbb9
commit
ae417b405a
2 files changed
+47
-2
No files matched your search
@@ -8452,8 +8452,10 @@ write_content_chunked(Stream &strm, const ContentProvider &content_provider,
|
||||
DataSink data_sink;
|
||||
|
||||
data_sink.write = [&](const char *d, size_t l) -> bool {
|
||||
if (ok) {
|
||||
data_available = l > 0;
|
||||
// Only done()/done_with_trailer() end a chunked body. A pass with nothing
|
||||
// to hand over is ordinary (an empty buffer popped off a queue), and a
|
||||
// zero-length chunk is the terminator, so it must not be emitted here.
|
||||
if (ok && l > 0) {
|
||||
offset += l;
|
||||
|
||||
std::string payload;
|
||||
|
||||
Reference in new issue
Block a user