Refactor HTTP identifier names (API Change):

fix #171

Several names and  HTTP identifiers are renamed to be
more consistent, self-explanatory, and concise:

* "Fields" is a collection of HTTP header fields (rfc7230 section 3.2)
* "Header" is the Start Line plus Fields. Another way to look at it is,
  the HTTP message minus the body.
* `basic_fields` replaces `basic_headers`
* `fields` replaces `headers`
* `Fields` replaces `Headers` in template parameter lists
* `header` replaces `message_headers`
* `header::fields` replaces `message_headers::fields`

The changes are cosmetic and do not affect run-time behavior.
This commit is contained in:
Vinnie Falco
2016-11-15 12:04:44 -05:00
parent 79be7f8b39
commit a0a335972f
64 changed files with 1220 additions and 1125 deletions
+45 -45
View File
@@ -9,7 +9,7 @@
#include <beast/http/message.hpp>
#include <beast/http/empty_body.hpp>
#include <beast/http/headers.hpp>
#include <beast/http/fields.hpp>
#include <beast/http/string_body.hpp>
#include <beast/unit_test/suite.hpp>
#include <type_traits>
@@ -73,66 +73,66 @@ public:
void testMessage()
{
static_assert(std::is_constructible<
message<true, default_body, headers>>::value, "");
message<true, default_body, fields>>::value, "");
static_assert(std::is_constructible<
message<true, one_arg_body, headers>, Arg1>::value, "");
message<true, one_arg_body, fields>, Arg1>::value, "");
static_assert(std::is_constructible<
message<true, one_arg_body, headers>, Arg1 const>::value, "");
message<true, one_arg_body, fields>, Arg1 const>::value, "");
static_assert(std::is_constructible<
message<true, one_arg_body, headers>, Arg1 const&>::value, "");
message<true, one_arg_body, fields>, Arg1 const&>::value, "");
static_assert(std::is_constructible<
message<true, one_arg_body, headers>, Arg1&&>::value, "");
message<true, one_arg_body, fields>, Arg1&&>::value, "");
static_assert(! std::is_constructible<
message<true, one_arg_body, headers>>::value, "");
message<true, one_arg_body, fields>>::value, "");
static_assert(std::is_constructible<
message<true, one_arg_body, headers>,
Arg1, headers::allocator_type>::value, "");
message<true, one_arg_body, fields>,
Arg1, fields::allocator_type>::value, "");
static_assert(std::is_constructible<
message<true, one_arg_body, headers>, std::piecewise_construct_t,
message<true, one_arg_body, fields>, std::piecewise_construct_t,
std::tuple<Arg1>>::value, "");
static_assert(std::is_constructible<
message<true, two_arg_body, headers>, std::piecewise_construct_t,
message<true, two_arg_body, fields>, std::piecewise_construct_t,
std::tuple<Arg1, Arg2>>::value, "");
static_assert(std::is_constructible<
message<true, two_arg_body, headers>, std::piecewise_construct_t,
std::tuple<Arg1, Arg2>, std::tuple<headers::allocator_type>>::value, "");
message<true, two_arg_body, fields>, std::piecewise_construct_t,
std::tuple<Arg1, Arg2>, std::tuple<fields::allocator_type>>::value, "");
{
Arg1 arg1;
message<true, one_arg_body, headers>{std::move(arg1)};
message<true, one_arg_body, fields>{std::move(arg1)};
BEAST_EXPECT(arg1.moved);
}
{
headers h;
fields h;
h.insert("User-Agent", "test");
message<true, one_arg_body, headers> m{Arg1{}, h};
message<true, one_arg_body, fields> m{Arg1{}, h};
BEAST_EXPECT(h["User-Agent"] == "test");
BEAST_EXPECT(m.headers["User-Agent"] == "test");
BEAST_EXPECT(m.fields["User-Agent"] == "test");
}
{
headers h;
fields h;
h.insert("User-Agent", "test");
message<true, one_arg_body, headers> m{Arg1{}, std::move(h)};
message<true, one_arg_body, fields> m{Arg1{}, std::move(h)};
BEAST_EXPECT(! h.exists("User-Agent"));
BEAST_EXPECT(m.headers["User-Agent"] == "test");
BEAST_EXPECT(m.fields["User-Agent"] == "test");
}
// swap
message<true, string_body, headers> m1;
message<true, string_body, headers> m2;
message<true, string_body, fields> m1;
message<true, string_body, fields> m2;
m1.url = "u";
m1.body = "1";
m1.headers.insert("h", "v");
m1.fields.insert("h", "v");
m2.method = "G";
m2.body = "2";
swap(m1, m2);
@@ -142,8 +142,8 @@ public:
BEAST_EXPECT(m2.url == "u");
BEAST_EXPECT(m1.body == "2");
BEAST_EXPECT(m2.body == "1");
BEAST_EXPECT(! m1.headers.exists("h"));
BEAST_EXPECT(m2.headers.exists("h"));
BEAST_EXPECT(! m1.fields.exists("h"));
BEAST_EXPECT(m2.fields.exists("h"));
}
struct MoveHeaders
@@ -168,13 +168,13 @@ public:
void testHeaders()
{
{
using req_type = request_headers;
using req_type = request_header;
static_assert(std::is_copy_constructible<req_type>::value, "");
static_assert(std::is_move_constructible<req_type>::value, "");
static_assert(std::is_copy_assignable<req_type>::value, "");
static_assert(std::is_move_assignable<req_type>::value, "");
using res_type = response_headers;
using res_type = response_header;
static_assert(std::is_copy_constructible<res_type>::value, "");
static_assert(std::is_move_constructible<res_type>::value, "");
static_assert(std::is_copy_assignable<res_type>::value, "");
@@ -183,12 +183,12 @@ public:
{
MoveHeaders h;
message_headers<true, MoveHeaders> r{std::move(h)};
header<true, MoveHeaders> r{std::move(h)};
BEAST_EXPECT(h.moved_from);
BEAST_EXPECT(r.headers.moved_to);
BEAST_EXPECT(r.fields.moved_to);
request<string_body, MoveHeaders> m{std::move(r)};
BEAST_EXPECT(r.headers.moved_from);
BEAST_EXPECT(m.headers.moved_to);
BEAST_EXPECT(r.fields.moved_from);
BEAST_EXPECT(m.fields.moved_to);
}
}
@@ -199,12 +199,12 @@ public:
m.method = "GET";
m.url = "/";
m.version = 11;
m.headers.insert("Upgrade", "test");
m.fields.insert("Upgrade", "test");
BEAST_EXPECT(! is_upgrade(m));
prepare(m, connection::upgrade);
BEAST_EXPECT(is_upgrade(m));
BEAST_EXPECT(m.headers["Connection"] == "upgrade");
BEAST_EXPECT(m.fields["Connection"] == "upgrade");
m.version = 10;
BEAST_EXPECT(! is_upgrade(m));
@@ -216,7 +216,7 @@ public:
request<empty_body> m;
m.version = 10;
BEAST_EXPECT(! is_upgrade(m));
m.headers.insert("Transfer-Encoding", "chunked");
m.fields.insert("Transfer-Encoding", "chunked");
try
{
prepare(m);
@@ -225,8 +225,8 @@ public:
catch(std::exception const&)
{
}
m.headers.erase("Transfer-Encoding");
m.headers.insert("Content-Length", "0");
m.fields.erase("Transfer-Encoding");
m.fields.insert("Content-Length", "0");
try
{
prepare(m);
@@ -236,8 +236,8 @@ public:
{
pass();
}
m.headers.erase("Content-Length");
m.headers.insert("Connection", "keep-alive");
m.fields.erase("Content-Length");
m.fields.insert("Connection", "keep-alive");
try
{
prepare(m);
@@ -248,19 +248,19 @@ public:
pass();
}
m.version = 11;
m.headers.erase("Connection");
m.headers.insert("Connection", "close");
m.fields.erase("Connection");
m.fields.insert("Connection", "close");
BEAST_EXPECT(! is_keep_alive(m));
}
void testSwap()
{
message<false, string_body, headers> m1;
message<false, string_body, headers> m2;
message<false, string_body, fields> m1;
message<false, string_body, fields> m2;
m1.status = 200;
m1.version = 10;
m1.body = "1";
m1.headers.insert("h", "v");
m1.fields.insert("h", "v");
m2.status = 404;
m2.reason = "OK";
m2.body = "2";
@@ -274,8 +274,8 @@ public:
BEAST_EXPECT(m2.version == 10);
BEAST_EXPECT(m1.body == "2");
BEAST_EXPECT(m2.body == "1");
BEAST_EXPECT(! m1.headers.exists("h"));
BEAST_EXPECT(m2.headers.exists("h"));
BEAST_EXPECT(! m1.fields.exists("h"));
BEAST_EXPECT(m2.fields.exists("h"));
}
void run() override