Add multiple content length error

fix #2468
This commit is contained in:
alandefreitas
2022-06-28 18:37:45 -03:00
committed by Klemens Morgenstern
parent b4e0f0d560
commit 5866e50438
6 changed files with 13 additions and 3 deletions

View File

@ -146,6 +146,9 @@ enum class error
/// An obs-fold exceeded an internal limit.
bad_obs_fold,
/// The response contains multiple and conflicting Content-Length.
multiple_content_length,
/** The parser is stale.
This happens when attempting to re-use a parser that has

View File

@ -809,6 +809,11 @@ do_field(field f,
ec = error::bad_content_length;
};
auto multiple_content_length = [&ec]
{
ec = error::multiple_content_length;
};
// conflicting field
if(f_ & flagChunked)
return bad_content_length();
@ -831,7 +836,7 @@ do_field(field f,
if (existing.has_value())
{
if (v != *existing)
return bad_content_length();
return multiple_content_length();
}
else
{

View File

@ -55,6 +55,7 @@ public:
case error::bad_chunk: return "bad chunk";
case error::bad_chunk_extension: return "bad chunk extension";
case error::bad_obs_fold: return "bad obs-fold";
case error::multiple_content_length: return "multiple Content-Length";
case error::stale_parser: return "stale parser";
case error::short_read: return "unexpected eof in body";

View File

@ -703,7 +703,7 @@ public:
failgrind<P>(c(",\r\n"), error::bad_content_length);
failgrind<P>(c("0,\r\n"), error::bad_content_length);
failgrind<P>(m("Content-Length: 0\r\n"
"Content-Length: 100\r\n"), error::bad_content_length);
"Content-Length: 100\r\n"), error::multiple_content_length);
}
void

View File

@ -65,6 +65,7 @@ public:
check("beast.http", error::bad_chunk);
check("beast.http", error::bad_chunk_extension);
check("beast.http", error::bad_obs_fold);
check("beast.http", error::multiple_content_length);
check("beast.http", error::stale_parser);
check("beast.http", error::short_read);

View File

@ -378,7 +378,7 @@ public:
response_parser<string_body> parser;
error_code ec;
parser.put(net::buffer(message), ec);
BEAST_EXPECTS(ec == error::bad_content_length, ec.message());
BEAST_EXPECTS(ec == error::multiple_content_length, ec.message());
};
// multiple contents lengths the same