New constructors for message:

The message class now behaves like a pair with respect to the construction
of the body and headers. Additional constructors allow construction of
just the body portion from a tuple, leaving the headers default
constructed.

Previous constructors are removed as they were a notational convenience
for assembling HTTP/1 requests and responses. They are not necessary
as this library aims at library writers and not end users.
This commit is contained in:
Vinnie Falco
2016-05-07 15:18:22 -04:00
parent e0956c36c1
commit 2b69831f49
13 changed files with 334 additions and 144 deletions

View File

@@ -135,8 +135,10 @@ public:
{
// auto content-length HTTP/1.0
{
message_v1<true, string_body, headers> m{{
"GET", "/", 10}};
message_v1<true, string_body, headers> m;
m.method = "GET";
m.url = "/";
m.version = 10;
m.headers.insert("User-Agent", "test");
m.body = "*";
prepare(m);
@@ -150,8 +152,10 @@ public:
}
// keep-alive HTTP/1.0
{
message_v1<true, string_body, headers> m{{
"GET", "/", 10}};
message_v1<true, string_body, headers> m;
m.method = "GET";
m.url = "/";
m.version = 10;
m.headers.insert("User-Agent", "test");
m.body = "*";
prepare(m, connection::keep_alive);
@@ -166,8 +170,10 @@ public:
}
// upgrade HTTP/1.0
{
message_v1<true, string_body, headers> m{{
"GET", "/", 10}};
message_v1<true, string_body, headers> m;
m.method = "GET";
m.url = "/";
m.version = 10;
m.headers.insert("User-Agent", "test");
m.body = "*";
try
@@ -182,8 +188,10 @@ public:
}
// no content-length HTTP/1.0
{
message_v1<true, test_body, headers> m{{
"GET", "/", 10}};
message_v1<true, test_body, headers> m;
m.method = "GET";
m.url = "/";
m.version = 10;
m.headers.insert("User-Agent", "test");
m.body = "*";
prepare(m);
@@ -200,8 +208,10 @@ public:
}
// auto content-length HTTP/1.1
{
message_v1<true, string_body, headers> m{{
"GET", "/", 11}};
message_v1<true, string_body, headers> m;
m.method = "GET";
m.url = "/";
m.version = 11;
m.headers.insert("User-Agent", "test");
m.body = "*";
prepare(m);
@@ -215,8 +225,10 @@ public:
}
// close HTTP/1.1
{
message_v1<true, string_body, headers> m{{
"GET", "/", 11}};
message_v1<true, string_body, headers> m;
m.method = "GET";
m.url = "/";
m.version = 11;
m.headers.insert("User-Agent", "test");
m.body = "*";
prepare(m, connection::close);
@@ -235,8 +247,10 @@ public:
}
// upgrade HTTP/1.1
{
message_v1<true, empty_body, headers> m{{
"GET", "/", 11}};
message_v1<true, empty_body, headers> m;
m.method = "GET";
m.url = "/";
m.version = 11;
m.headers.insert("User-Agent", "test");
prepare(m, connection::upgrade);
expect(str(m) ==
@@ -248,8 +262,10 @@ public:
}
// no content-length HTTP/1.1
{
message_v1<true, test_body, headers> m{{
"GET", "/", 11}};
message_v1<true, test_body, headers> m;
m.method = "GET";
m.url = "/";
m.version = 11;
m.headers.insert("User-Agent", "test");
m.body = "*";
prepare(m);
@@ -270,8 +286,10 @@ public:
void testConvert()
{
message_v1<true, string_body, headers> m{{
"GET", "/", 11}};
message_v1<true, string_body, headers> m;
m.method = "GET";
m.url = "/";
m.version = 11;
m.headers.insert("User-Agent", "test");
m.body = "*";
prepare(m);