Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion include/boost/beast/http/impl/message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ prepare_payload(std::false_type)
{
auto const n = payload_size();
if( (! n || *n > 0) && (
(status_class(this->result()) == status_class::informational ||
(to_status_class(this->result()) == status_class::informational ||
this->result() == status::no_content ||
this->result() == status::not_modified)))
{
Expand Down
26 changes: 26 additions & 0 deletions test/beast/http/fields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,32 @@ class fields_test : public beast::unit_test::suite
BEAST_EXPECT(res.count(field::content_length) == 0);
BEAST_EXPECT(res[field::transfer_encoding] == "chunked");
}

// a body is not allowed on 1xx, 204 or 304
{
for(auto code : {
status::continue_, // 100
status::switching_protocols,// 101
status::processing, // 102
status::early_hints, // 103
status::no_content, // 204
status::not_modified}) // 304
{
response<sized_body> res;
res.version(11);
res.result(code);
res.body() = 1;
BEAST_THROWS(res.prepare_payload(), std::invalid_argument);
}

// an ordinary 2xx response with a body is unaffected
response<sized_body> res;
res.version(11);
res.result(status::ok);
res.body() = 1;
res.prepare_payload();
BEAST_EXPECT(res[field::content_length] == "1");
}
}

void
Expand Down
Loading