Commit 841d653
committed
Give DataSink's optional callbacks safe defaults
DataSink has four callbacks, but only write is assigned by every writer
that hands a sink to a content provider:
write_content_with_progress() write, is_writable
write_content_without_length() write, is_writable, done
write_content_chunked() all four
send_with_content_provider...() write
get_multipart_content_provider() write, done (cur_sink)
A provider that calls one of the unassigned ones invokes an empty
std::function and throws std::bad_function_call. Nothing on that path
catches it, so it unwinds out of the thread running the provider and
terminates the process. The README's own idiom is enough to hit it:
sink.done() is documented for the without-length overload, but a
provider registered through set_content_provider() with a length gets a
sink where done is empty.
Default the three optional callbacks instead. A sink is writable unless
a writer says otherwise, and a sink that cannot carry trailers still has
to finish, so done_with_trailer() falls back to done(). Capturing this
for that is safe because DataSink is neither copyable nor movable.
A no-op done() alone would only trade the crash for a hang on the two
length-framed paths: both loop until offset reaches the promised length,
so a provider that reports itself done without writing would be called
again immediately, forever. Both now record that the provider finished
and stop, and the short body is reported as a write error. The client
path gains that check for the compressor-failure exit as well, which
used to send a truncated request body without reporting anything.
cur_sink in get_multipart_content_provider() now forwards is_writable
from the outer sink, so a provider item asking whether it may keep going
gets the stream's answer rather than the default.1 parent 254e576 commit 841d653
2 files changed
Lines changed: 153 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1429 | 1429 | | |
1430 | 1430 | | |
1431 | 1431 | | |
1432 | | - | |
1433 | | - | |
1434 | | - | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
1435 | 1442 | | |
1436 | 1443 | | |
1437 | 1444 | | |
| |||
8298 | 8305 | | |
8299 | 8306 | | |
8300 | 8307 | | |
| 8308 | + | |
8301 | 8309 | | |
8302 | 8310 | | |
8303 | 8311 | | |
| |||
8321 | 8329 | | |
8322 | 8330 | | |
8323 | 8331 | | |
8324 | | - | |
| 8332 | + | |
| 8333 | + | |
| 8334 | + | |
| 8335 | + | |
| 8336 | + | |
| 8337 | + | |
8325 | 8338 | | |
8326 | 8339 | | |
8327 | 8340 | | |
| |||
8334 | 8347 | | |
8335 | 8348 | | |
8336 | 8349 | | |
8337 | | - | |
| 8350 | + | |
8338 | 8351 | | |
8339 | 8352 | | |
8340 | 8353 | | |
| |||
15312 | 15325 | | |
15313 | 15326 | | |
15314 | 15327 | | |
| 15328 | + | |
15315 | 15329 | | |
15316 | 15330 | | |
15317 | 15331 | | |
| |||
15335 | 15349 | | |
15336 | 15350 | | |
15337 | 15351 | | |
15338 | | - | |
| 15352 | + | |
| 15353 | + | |
| 15354 | + | |
| 15355 | + | |
| 15356 | + | |
| 15357 | + | |
15339 | 15358 | | |
15340 | 15359 | | |
15341 | 15360 | | |
15342 | 15361 | | |
15343 | 15362 | | |
15344 | 15363 | | |
| 15364 | + | |
| 15365 | + | |
| 15366 | + | |
| 15367 | + | |
| 15368 | + | |
| 15369 | + | |
| 15370 | + | |
| 15371 | + | |
| 15372 | + | |
15345 | 15373 | | |
15346 | 15374 | | |
15347 | 15375 | | |
| |||
15644 | 15672 | | |
15645 | 15673 | | |
15646 | 15674 | | |
| 15675 | + | |
| 15676 | + | |
| 15677 | + | |
15647 | 15678 | | |
15648 | 15679 | | |
15649 | 15680 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10502 | 10502 | | |
10503 | 10503 | | |
10504 | 10504 | | |
| 10505 | + | |
| 10506 | + | |
| 10507 | + | |
| 10508 | + | |
| 10509 | + | |
| 10510 | + | |
| 10511 | + | |
| 10512 | + | |
| 10513 | + | |
| 10514 | + | |
| 10515 | + | |
| 10516 | + | |
| 10517 | + | |
| 10518 | + | |
| 10519 | + | |
| 10520 | + | |
| 10521 | + | |
| 10522 | + | |
| 10523 | + | |
| 10524 | + | |
| 10525 | + | |
| 10526 | + | |
| 10527 | + | |
| 10528 | + | |
| 10529 | + | |
| 10530 | + | |
| 10531 | + | |
| 10532 | + | |
| 10533 | + | |
| 10534 | + | |
| 10535 | + | |
| 10536 | + | |
| 10537 | + | |
| 10538 | + | |
| 10539 | + | |
| 10540 | + | |
| 10541 | + | |
| 10542 | + | |
| 10543 | + | |
| 10544 | + | |
| 10545 | + | |
| 10546 | + | |
| 10547 | + | |
| 10548 | + | |
| 10549 | + | |
| 10550 | + | |
| 10551 | + | |
| 10552 | + | |
| 10553 | + | |
| 10554 | + | |
| 10555 | + | |
| 10556 | + | |
| 10557 | + | |
| 10558 | + | |
| 10559 | + | |
| 10560 | + | |
| 10561 | + | |
| 10562 | + | |
| 10563 | + | |
| 10564 | + | |
| 10565 | + | |
| 10566 | + | |
| 10567 | + | |
| 10568 | + | |
| 10569 | + | |
| 10570 | + | |
| 10571 | + | |
| 10572 | + | |
| 10573 | + | |
| 10574 | + | |
| 10575 | + | |
| 10576 | + | |
| 10577 | + | |
| 10578 | + | |
| 10579 | + | |
| 10580 | + | |
| 10581 | + | |
| 10582 | + | |
| 10583 | + | |
| 10584 | + | |
| 10585 | + | |
| 10586 | + | |
| 10587 | + | |
| 10588 | + | |
| 10589 | + | |
| 10590 | + | |
| 10591 | + | |
| 10592 | + | |
| 10593 | + | |
| 10594 | + | |
| 10595 | + | |
| 10596 | + | |
| 10597 | + | |
| 10598 | + | |
| 10599 | + | |
| 10600 | + | |
| 10601 | + | |
| 10602 | + | |
| 10603 | + | |
| 10604 | + | |
| 10605 | + | |
| 10606 | + | |
| 10607 | + | |
| 10608 | + | |
| 10609 | + | |
| 10610 | + | |
| 10611 | + | |
| 10612 | + | |
| 10613 | + | |
| 10614 | + | |
| 10615 | + | |
| 10616 | + | |
| 10617 | + | |
| 10618 | + | |
| 10619 | + | |
| 10620 | + | |
10505 | 10621 | | |
10506 | 10622 | | |
10507 | 10623 | | |
| |||
0 commit comments