Skip to content

Commit 482d862

Browse files
authored
server : handle unsuccessful sink.write in chunked stream provider (#21478)
Check the return value of sink.write() in the chunked content provider and return false when the write fails, matching cpp-httplib's own streaming contract. This prevents logging chunks as sent when the sink rejected them and properly aborts the stream on connection failure.
1 parent 3979f2b commit 482d862

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

tools/server/server-http.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,9 @@ static void process_handler_response(server_http_req_ptr && request, server_http
397397
std::string chunk;
398398
bool has_next = response->next(chunk);
399399
if (!chunk.empty()) {
400-
// TODO: maybe handle sink.write unsuccessful? for now, we rely on is_connection_closed()
401-
sink.write(chunk.data(), chunk.size());
400+
if (!sink.write(chunk.data(), chunk.size())) {
401+
return false;
402+
}
402403
SRV_DBG("http: streamed chunk: %s\n", chunk.c_str());
403404
}
404405
if (!has_next) {

0 commit comments

Comments
 (0)