Skip to content

Commit 7f401cf

Browse files
committed
fix: prevent repeated sink::write calls when more==false
1 parent cf22661 commit 7f401cf

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

include/boost/http_proto/string_body.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ namespace http_proto {
2828
@code
2929
serializer sr(ctx);
3030
response res(status::not_found);
31-
3231
std::string body =
3332
"<html>\n"
3433
" <body>\n"
3534
" <h1>404 Not Found</h1>\n"
3635
" <p>Sorry, the page does not exist.</p>\n"
3736
" </body>\n"
3837
"</html>\n";
38+
res.set_payload_size(body.size());
3939
sr.start<string_body>(res, std::move(body));
4040
@endcode
4141

src/parser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ parse(
11161116
break;
11171117

11181118
case content_coding::gzip:
1119-
if(!svc_.cfg.apply_deflate_decoder)
1119+
if(!svc_.cfg.apply_gzip_decoder)
11201120
goto no_filter;
11211121
filter_ = &ws_.emplace<zlib_filter>(
11221122
ctx_, ws_, svc_.cfg.zlib_window_bits + 16);
@@ -1735,7 +1735,7 @@ apply_filter(
17351735
{
17361736
cb1_.commit(f_rs.out_bytes);
17371737
auto sink_rs = sink_->write(
1738-
cb1_.data(), !f_rs.finished);
1738+
cb1_.data(), !f_rs.finished || more);
17391739
cb1_.consume(sink_rs.bytes);
17401740
if(sink_rs.ec.failed())
17411741
{

test/unit/compression.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ struct zlib_test
246246
class source_t : public source
247247
{
248248
buffers::const_buffer body_;
249+
bool done_ = false;
249250

250251
public:
251252
source_t(buffers::const_buffer body)
@@ -256,11 +257,14 @@ struct zlib_test
256257
results
257258
on_read(buffers::mutable_buffer b)
258259
{
260+
BOOST_TEST_NOT(done_);
261+
259262
results rs;
260263
auto n = buffers::copy(b, body_);
261264
body_ = buffers::sans_prefix(body_, n);
262265
rs.bytes = n;
263266
rs.finished = (body_.size() == 0);
267+
done_ = rs.finished;
264268
return rs;
265269
}
266270
};
@@ -561,6 +565,7 @@ struct zlib_test
561565
class sink_t : public sink
562566
{
563567
std::string body_;
568+
bool done_ = false;
564569

565570
public:
566571
std::string
@@ -572,8 +577,11 @@ struct zlib_test
572577
results
573578
on_write(
574579
buffers::const_buffer b,
575-
bool) override
580+
bool more) override
576581
{
582+
BOOST_TEST_NOT(done_);
583+
done_ = !more;
584+
577585
body_.append(
578586
static_cast<const char*>(b.data()),
579587
b.size());

0 commit comments

Comments
 (0)