diff --git a/include/boost/beast/http/fields.hpp b/include/boost/beast/http/fields.hpp index d4b06ac7..72cedb28 100644 --- a/include/boost/beast/http/fields.hpp +++ b/include/boost/beast/http/fields.hpp @@ -421,6 +421,7 @@ public: If one or more fields with the same name already exist, the new field will be inserted after the last field with the matching name, in serialization order. + The value can be an empty string. @param name The field name. @@ -439,6 +440,7 @@ public: If one or more fields with the same name already exist, the new field will be inserted after the last field with the matching name, in serialization order. + The value can be an empty string. @param name The field name. @@ -457,6 +459,7 @@ public: If one or more fields with the same name already exist, the new field will be inserted after the last field with the matching name, in serialization order. + The value can be an empty string. @param name The field name. @@ -477,13 +480,14 @@ public: /** Set a field value, removing any other instances of that field. First removes any values with matching field names, then - inserts the new field value. + inserts the new field value. The value may be an empty string. @param name The field name. @param value The value of the field, as a @ref boost::beast::string_view @return The field value. + */ void set(field name, string_view const& value); @@ -494,7 +498,7 @@ public: /** Set a field value, removing any other instances of that field. First removes any values with matching field names, then - inserts the new field value. + inserts the new field value. The value can be an empty string. @param name The field name. diff --git a/test/beast/http/fields.cpp b/test/beast/http/fields.cpp index 0a9fa0eb..03dab6da 100644 --- a/test/beast/http/fields.cpp +++ b/test/beast/http/fields.cpp @@ -1072,6 +1072,20 @@ public: BOOST_STATIC_ASSERT(( insert_test::value)); } + void + testEmpty() + { + beast::http::fields req; + req.insert("abc", ""); + req.set("cba", ""); + auto itr = req.find("abc"); + BEAST_EXPECT(itr != req.end()); + BEAST_EXPECT(itr->value().empty()); + itr = req.find("cba"); + BEAST_EXPECT(itr != req.end()); + BEAST_EXPECT(itr->value().empty()); + } + void run() override { @@ -1089,6 +1103,7 @@ public: testIssue1828(); boost::ignore_unused(&fields_test::testIssue2085); + testEmpty(); } };