diff --git a/CHANGELOG.md b/CHANGELOG.md index e707cdb3..f542a58d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +1.0.0-b15 + +* rfc7230 section 3.3.2 compliance + +-------------------------------------------------------------------------------- + 1.0.0-b14 * Add missing rebind to handler_alloc diff --git a/include/beast/http/impl/message_v1.ipp b/include/beast/http/impl/message_v1.ipp index e2a2568d..dafe19d6 100644 --- a/include/beast/http/impl/message_v1.ipp +++ b/include/beast/http/impl/message_v1.ipp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -139,9 +140,35 @@ prepare(message_v1& msg, { if(pi.content_length) { - // VFALCO TODO Use a static string here - msg.headers.insert("Content-Length", - std::to_string(*pi.content_length)); + struct set_field + { + void + operator()(message_v1& msg, + detail::prepare_info const& pi) const + { + using beast::detail::ci_equal; + if(*pi.content_length > 0 || + ci_equal(msg.method, "POST")) + { + msg.headers.insert("Content-Length", + std::to_string(*pi.content_length)); + } + } + + void + operator()(message_v1& msg, + detail::prepare_info const& pi) const + { + if((msg.status / 100 ) != 1 && + msg.status != 204 && + msg.status != 304) + { + msg.headers.insert("Content-Length", + std::to_string(*pi.content_length)); + } + } + }; + set_field{}(msg, pi); } else if(msg.version >= 11) {