iostream/http: Fix output_stream::write(temporary_buffer) overload #2436
+56
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, calling the
write(temporary_buffer<char>)
overload on anoutput_stream<char>
obtained fromhttp::reply::write_body
would cause an abort.This commit fixes this by providing a helper function (in the
data_sink_impl
base class) namedfallback_put
, which classes that inherit from this base class can use to implement theput(net::packet)
overload. Also, this commit letshttp_chunked_data_sink_impl
andhttp_content_length_data_sink_impl
make use of this helper.fallback_put(net::packet)
works simply by extracting the temporary_buffers contained in the packet, and calling theput(temporary_buffer<char>)
overload for eachtemporary_buffer
.Note that we create this
fallback_put
function instead of defining the virtual memberput(net::packet)
function in thedata_sink_impl
class, to avoidput(net::packet)
andput(temporary_buffer<char>)
calling each other leading to infinite recursion.This commit also adds unit tests to
tests/unit/httpd_test.cc
for testing thewrite
overload withhttp_chunked_data_sink_impl
andhttp_content_length_data_sink_impl
.Thanks to Pavel (xemul) for his help.
Fixes #1701