Skip to content

Check if stream is writable to avoid infinite loop in write_content_chunked while using SSE #1478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -3643,7 +3643,7 @@ inline bool write_content(Stream &strm, const ContentProvider &content_provider,

data_sink.is_writable = [&](void) { return ok && strm.is_writable(); };

while (offset < end_offset && !is_shutting_down()) {
while (offset < end_offset && !is_shutting_down() && strm.is_writable()) {
if (!content_provider(offset, end_offset - offset, data_sink)) {
error = Error::Canceled;
return false;
Expand Down Expand Up @@ -3689,7 +3689,7 @@ write_content_without_length(Stream &strm,

data_sink.is_writable = [&](void) { return ok && strm.is_writable(); };

while (data_available && !is_shutting_down()) {
while (data_available && !is_shutting_down() && strm.is_writable()) {
if (!content_provider(offset, 0, data_sink)) { return false; }
if (!ok) { return false; }
}
Expand Down Expand Up @@ -3761,7 +3761,7 @@ write_content_chunked(Stream &strm, const ContentProvider &content_provider,

data_sink.is_writable = [&](void) { return ok && strm.is_writable(); };

while (data_available && !is_shutting_down()) {
while (data_available && !is_shutting_down() && strm.is_writable()) {
if (!content_provider(offset, 0, data_sink)) {
error = Error::Canceled;
return false;
Expand Down