mirror of
https://github.com/boostorg/beast.git
synced 2026-08-03 20:14:17 +02:00
reject 1xx responses with a body in prepare_payload
This commit is contained in:
committed by
Mohammad Nejati
parent
56a7c3af49
commit
3c1f91fa62
@@ -390,7 +390,7 @@ prepare_payload(std::false_type)
|
|||||||
{
|
{
|
||||||
auto const n = payload_size();
|
auto const n = payload_size();
|
||||||
if( (! n || *n > 0) && (
|
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::no_content ||
|
||||||
this->result() == status::not_modified)))
|
this->result() == status::not_modified)))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -672,6 +672,32 @@ public:
|
|||||||
BEAST_EXPECT(res.count(field::content_length) == 0);
|
BEAST_EXPECT(res.count(field::content_length) == 0);
|
||||||
BEAST_EXPECT(res[field::transfer_encoding] == "chunked");
|
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
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user