basic_fields refactor (API Change):

* Container interface more closely matches std::vector

* While preserving the invariant that duplicate fields
  with the same case-insensitive name have their order
  preserved.
This commit is contained in:
Vinnie Falco committed 2017-07-20 08:12:19 -07:00
1 parent 0d70d90b75
commit 8c4136bb73
11 files changed
+692 -493

No files matched your search

+54 -2
View File
@@ -273,8 +273,8 @@ public:
{
fields f;
f.insert(field::user_agent, "x");
BEAST_EXPECT(f.exists(field::user_agent));
BEAST_EXPECT(f.exists(to_string(field::user_agent)));
BEAST_EXPECT(f.count(field::user_agent));
BEAST_EXPECT(f.count(to_string(field::user_agent)));
BEAST_EXPECT(f.count(field::user_agent) == 1);
BEAST_EXPECT(f.count(to_string(field::user_agent)) == 1);
f.insert(field::user_agent, "y");
@@ -326,12 +326,64 @@ public:
BEAST_EXPECT(size(f) == 2);
}
void
testContainer()
{
{
// group fields
fields f;
f.insert(field::age, 1);
f.insert(field::body, 2);
f.insert(field::close, 3);
f.insert(field::body, 4);
BEAST_EXPECT(std::next(f.begin(), 0)->name() == field::age);
BEAST_EXPECT(std::next(f.begin(), 1)->name() == field::body);
BEAST_EXPECT(std::next(f.begin(), 2)->name() == field::body);
BEAST_EXPECT(std::next(f.begin(), 3)->name() == field::close);
BEAST_EXPECT(std::next(f.begin(), 0)->name_string() == "Age");
BEAST_EXPECT(std::next(f.begin(), 1)->name_string() == "Body");
BEAST_EXPECT(std::next(f.begin(), 2)->name_string() == "Body");
BEAST_EXPECT(std::next(f.begin(), 3)->name_string() == "Close");
BEAST_EXPECT(std::next(f.begin(), 0)->value() == "1");
BEAST_EXPECT(std::next(f.begin(), 1)->value() == "2");
BEAST_EXPECT(std::next(f.begin(), 2)->value() == "4");
BEAST_EXPECT(std::next(f.begin(), 3)->value() == "3");
BEAST_EXPECT(f.erase(field::body) == 2);
BEAST_EXPECT(std::next(f.begin(), 0)->name_string() == "Age");
BEAST_EXPECT(std::next(f.begin(), 1)->name_string() == "Close");
}
{
// group fields, case insensitive
fields f;
f.insert("a", 1);
f.insert("ab", 2);
f.insert("b", 3);
f.insert("AB", 4);
BEAST_EXPECT(std::next(f.begin(), 0)->name() == field::unknown);
BEAST_EXPECT(std::next(f.begin(), 1)->name() == field::unknown);
BEAST_EXPECT(std::next(f.begin(), 2)->name() == field::unknown);
BEAST_EXPECT(std::next(f.begin(), 3)->name() == field::unknown);
BEAST_EXPECT(std::next(f.begin(), 0)->name_string() == "a");
BEAST_EXPECT(std::next(f.begin(), 1)->name_string() == "ab");
BEAST_EXPECT(std::next(f.begin(), 2)->name_string() == "AB");
BEAST_EXPECT(std::next(f.begin(), 3)->name_string() == "b");
BEAST_EXPECT(std::next(f.begin(), 0)->value() == "1");
BEAST_EXPECT(std::next(f.begin(), 1)->value() == "2");
BEAST_EXPECT(std::next(f.begin(), 2)->value() == "4");
BEAST_EXPECT(std::next(f.begin(), 3)->value() == "3");
BEAST_EXPECT(f.erase("Ab") == 2);
BEAST_EXPECT(std::next(f.begin(), 0)->name_string() == "a");
BEAST_EXPECT(std::next(f.begin(), 1)->name_string() == "b");
}
}
void run() override
{
testMembers();
testHeaders();
testRFC2616();
testErase();
testContainer();
}
};
+5 -5
View File
@@ -124,7 +124,7 @@ public:
header<true> h;
h.insert(field::user_agent, "test");
request<one_arg_body> m{Arg1{}, std::move(h)};
BEAST_EXPECT(! h.exists("User-Agent"));
BEAST_EXPECT(! h.count(http::field::user_agent));
BEAST_EXPECT(m["User-Agent"] == "test");
}
@@ -143,8 +143,8 @@ public:
BEAST_EXPECT(m2.target() == "u");
BEAST_EXPECT(m1.body == "2");
BEAST_EXPECT(m2.body == "1");
BEAST_EXPECT(! m1.exists("h"));
BEAST_EXPECT(m2.exists("h"));
BEAST_EXPECT(! m1.count("h"));
BEAST_EXPECT(m2.count("h"));
}
struct MoveFields : fields
@@ -217,8 +217,8 @@ public:
BEAST_EXPECT(m2.version == 10);
BEAST_EXPECT(m1.body == "2");
BEAST_EXPECT(m2.body == "1");
BEAST_EXPECT(! m1.exists("h"));
BEAST_EXPECT(m2.exists("h"));
BEAST_EXPECT(! m1.count("h"));
BEAST_EXPECT(m2.count("h"));
}
void
+1 -1
View File
@@ -88,7 +88,7 @@ boost::asio::ip::tcp::socket sock{ios};
//[ws_snippet_10
response_type res;
ws.handshake(res, "localhost", "/");
if(! res.exists(http::field::sec_websocket_protocol))
if(! res.count(http::field::sec_websocket_protocol))
throw std::invalid_argument("missing subprotocols");
//]