diff --git a/include/boost/beast/http/error.hpp b/include/boost/beast/http/error.hpp index ab6216b1..c04c7300 100644 --- a/include/boost/beast/http/error.hpp +++ b/include/boost/beast/http/error.hpp @@ -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 diff --git a/include/boost/beast/http/impl/basic_parser.ipp b/include/boost/beast/http/impl/basic_parser.ipp index 4eff491c..c5688156 100644 --- a/include/boost/beast/http/impl/basic_parser.ipp +++ b/include/boost/beast/http/impl/basic_parser.ipp @@ -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 { diff --git a/include/boost/beast/http/impl/error.ipp b/include/boost/beast/http/impl/error.ipp index 2443c818..439b691b 100644 --- a/include/boost/beast/http/impl/error.ipp +++ b/include/boost/beast/http/impl/error.ipp @@ -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"; diff --git a/test/beast/http/basic_parser.cpp b/test/beast/http/basic_parser.cpp index ef809e78..0a21d893 100644 --- a/test/beast/http/basic_parser.cpp +++ b/test/beast/http/basic_parser.cpp @@ -703,7 +703,7 @@ public: failgrind

(c(",\r\n"), error::bad_content_length); failgrind

(c("0,\r\n"), error::bad_content_length); failgrind

(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 diff --git a/test/beast/http/error.cpp b/test/beast/http/error.cpp index 8689cd9d..248f1cf9 100644 --- a/test/beast/http/error.cpp +++ b/test/beast/http/error.cpp @@ -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); diff --git a/test/beast/http/parser.cpp b/test/beast/http/parser.cpp index 9d59511d..8641e418 100644 --- a/test/beast/http/parser.cpp +++ b/test/beast/http/parser.cpp @@ -378,7 +378,7 @@ public: response_parser 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