message::body is a member function (API Change):

fix #778

* The body data member is replaced with accessor
  member functions.

Actions Required:

* Call member function message::body instead of accessing
  the data member at call sites.
This commit is contained in:
Vinnie Falco committed 2017-09-12 17:12:12 -07:00
1 parent 0d4d239d05
commit 54fe7cacf7
36 files changed
+248 -182

No files matched your search

+1 -1
View File
@@ -66,7 +66,7 @@ public:
multi_buffer b;
read(ts, b, p);
auto const& m = p.get();
BEAST_EXPECT(to_string(m.body.data()) == "xyz");
BEAST_EXPECT(to_string(m.body().data()) == "xyz");
BEAST_EXPECT(to_string(m) == s);
}
};
+3 -3
View File
@@ -475,7 +475,7 @@ public:
request<sized_body> req;
req.version = 11;
req.method(verb::get);
req.body = 50;
req.body() = 50;
req.prepare_payload();
BEAST_EXPECT(req[field::content_length] == "50");
@@ -515,7 +515,7 @@ public:
request<sized_body> req;
req.version = 11;
req.method(verb::put);
req.body = 50;
req.body() = 50;
req.prepare_payload();
BEAST_EXPECT(req[field::content_length] == "50");
@@ -580,7 +580,7 @@ public:
{
response<sized_body> res;
res.version = 11;
res.body = 50;
res.body() = 50;
res.prepare_payload();
BEAST_EXPECT(res[field::content_length] == "50");
+2 -2
View File
@@ -54,7 +54,7 @@ public:
response_parser<basic_file_body<File>> p;
p.eager(true);
p.get().body.open(
p.get().body().open(
temp.string<std::string>().c_str(), file_mode::write, ec);
BEAST_EXPECTS(! ec, ec.message());
@@ -78,7 +78,7 @@ public:
{
response<basic_file_body<File>> res{status::ok, 11};
res.set(field::server, "test");
res.body.open(temp.string<std::string>().c_str(),
res.body().open(temp.string<std::string>().c_str(),
file_mode::scan, ec);
BEAST_EXPECTS(! ec, ec.message());
res.prepare_payload();
+12 -12
View File
@@ -156,17 +156,17 @@ public:
request<string_body> m1;
request<string_body> m2;
m1.target("u");
m1.body = "1";
m1.body() = "1";
m1.insert("h", "v");
m2.method_string("G");
m2.body = "2";
m2.body() = "2";
swap(m1, m2);
BEAST_EXPECT(m1.method_string() == "G");
BEAST_EXPECT(m2.method_string().empty());
BEAST_EXPECT(m1.target().empty());
BEAST_EXPECT(m2.target() == "u");
BEAST_EXPECT(m1.body == "2");
BEAST_EXPECT(m2.body == "1");
BEAST_EXPECT(m1.body() == "2");
BEAST_EXPECT(m2.body() == "1");
BEAST_EXPECT(! m1.count("h"));
BEAST_EXPECT(m2.count("h"));
}
@@ -231,7 +231,7 @@ public:
BEAST_EXPECT(req.version == 11);
BEAST_EXPECT(req.method() == verb::get);
BEAST_EXPECT(req.target() == "/");
BEAST_EXPECT(req.body == "Hello");
BEAST_EXPECT(req.body() == "Hello");
}
{
request<string_body, test_fields> req{
@@ -239,7 +239,7 @@ public:
BEAST_EXPECT(req.version == 11);
BEAST_EXPECT(req.method() == verb::get);
BEAST_EXPECT(req.target() == "/");
BEAST_EXPECT(req.body == "Hello");
BEAST_EXPECT(req.body() == "Hello");
}
{
response<string_body> res;
@@ -258,7 +258,7 @@ public:
BEAST_EXPECT(res.version == 10);
BEAST_EXPECT(res.result() == status::bad_request);
BEAST_EXPECT(res.reason() == "Bad Request");
BEAST_EXPECT(res.body == "Hello");
BEAST_EXPECT(res.body() == "Hello");
}
{
response<string_body, test_fields> res{
@@ -266,7 +266,7 @@ public:
BEAST_EXPECT(res.version == 10);
BEAST_EXPECT(res.result() == status::bad_request);
BEAST_EXPECT(res.reason() == "Bad Request");
BEAST_EXPECT(res.body == "Hello");
BEAST_EXPECT(res.body() == "Hello");
}
}
@@ -277,10 +277,10 @@ public:
response<string_body> m2;
m1.result(status::ok);
m1.version = 10;
m1.body = "1";
m1.body() = "1";
m1.insert("h", "v");
m2.result(status::not_found);
m2.body = "2";
m2.body() = "2";
m2.version = 11;
swap(m1, m2);
BEAST_EXPECT(m1.result() == status::not_found);
@@ -291,8 +291,8 @@ public:
BEAST_EXPECT(m2.reason() == "OK");
BEAST_EXPECT(m1.version == 11);
BEAST_EXPECT(m2.version == 10);
BEAST_EXPECT(m1.body == "2");
BEAST_EXPECT(m2.body == "1");
BEAST_EXPECT(m1.body() == "2");
BEAST_EXPECT(m2.body() == "1");
BEAST_EXPECT(! m1.count("h"));
BEAST_EXPECT(m2.count("h"));
}
+5 -5
View File
@@ -135,7 +135,7 @@ public:
BEAST_EXPECT(m.result() == status::ok);
BEAST_EXPECT(m.reason() == "OK");
BEAST_EXPECT(m["Server"] == "test");
BEAST_EXPECT(m.body == "Hello, world!");
BEAST_EXPECT(m.body() == "Hello, world!");
}
);
doMatrix<false>(
@@ -165,7 +165,7 @@ public:
BEAST_EXPECT(m["Transfer-Encoding"] == "chunked");
BEAST_EXPECT(m["Expires"] == "never");
BEAST_EXPECT(m["MD5-Fingerprint"] == "-");
BEAST_EXPECT(m.body == "*****--");
BEAST_EXPECT(m.body() == "*****--");
}
);
doMatrix<false>(
@@ -177,7 +177,7 @@ public:
[&](parser_type<false> const& p)
{
auto const& m = p.get();
BEAST_EXPECT(m.body == "*****");
BEAST_EXPECT(m.body() == "*****");
}
);
doMatrix<true>(
@@ -228,7 +228,7 @@ public:
BEAST_EXPECT(m.target() == "/");
BEAST_EXPECT(m.version == 11);
BEAST_EXPECT(m["User-Agent"] == "test");
BEAST_EXPECT(m.body == "*");
BEAST_EXPECT(m.body() == "*");
}
{
// test partial parsing of final chunk
@@ -247,7 +247,7 @@ public:
b.consume(used);
BEAST_EXPECT(! ec);
BEAST_EXPECT(! p.is_done());
BEAST_EXPECT(p.get().body == "*");
BEAST_EXPECT(p.get().body() == "*");
ostream(b) <<
"\r\n"
"0;d;e=3;f=\"4\"\r\n"
+1 -1
View File
@@ -102,7 +102,7 @@ public:
lambda visit;
error_code ec;
response<string_body> res;
res.body.append(1000, '*');
res.body().append(1000, '*');
serializer<false, string_body> sr{res};
sr.limit(limit);
for(;;)
+6 -6
View File
@@ -27,12 +27,12 @@ struct span_body_test
using B = span_body<char const>;
request<B> req;
BEAST_EXPECT(req.body.size() == 0);
BEAST_EXPECT(B::size(req.body) == 0);
BEAST_EXPECT(req.body().size() == 0);
BEAST_EXPECT(B::size(req.body()) == 0);
req.body = B::value_type("xyz", 3);
BEAST_EXPECT(req.body.size() == 3);
BEAST_EXPECT(B::size(req.body) == 3);
req.body() = B::value_type("xyz", 3);
BEAST_EXPECT(req.body().size() == 3);
BEAST_EXPECT(B::size(req.body()) == 3);
B::reader r{req};
error_code ec;
@@ -49,7 +49,7 @@ struct span_body_test
char buf[5];
using B = span_body<char>;
request<B> req;
req.body = span<char>{buf, sizeof(buf)};
req.body() = span<char>{buf, sizeof(buf)};
B::writer w{req};
error_code ec;
w.init(boost::none, ec);
+27 -27
View File
@@ -50,7 +50,7 @@ public:
explicit
reader(message<isRequest,
unsized_body, Allocator> const& msg)
: body_(msg.body)
: body_(msg.body())
{
}
@@ -95,7 +95,7 @@ public:
explicit
reader(message<isRequest,
test_body, Fields> const& msg)
: body_(msg.body)
: body_(msg.body())
{
}
@@ -232,7 +232,7 @@ public:
explicit
reader(message<isRequest,
fail_body, Allocator> const& msg)
: body_(msg.body)
: body_(msg.body())
{
}
@@ -292,7 +292,7 @@ public:
try
{
read(ts, b, m);
return m.body == body;
return m.body() == body;
}
catch(std::exception const& e)
{
@@ -323,7 +323,7 @@ public:
m.result(status::ok);
m.set(field::server, "test");
m.set(field::content_length, "5");
m.body = "*****";
m.body() = "*****";
error_code ec;
test::stream ts{ios_}, tr{ios_};
ts.connect(tr);
@@ -342,7 +342,7 @@ public:
m.result(status::ok);
m.set(field::server, "test");
m.set(field::transfer_encoding, "chunked");
m.body = "*****";
m.body() = "*****";
error_code ec;
test::stream ts{ios_}, tr{ios_};
ts.connect(tr);
@@ -374,7 +374,7 @@ public:
m.set(field::user_agent, "test");
m.set(field::connection, "keep-alive");
m.set(field::content_length, "5");
m.body = "*****";
m.body() = "*****";
try
{
write(ts, m);
@@ -403,7 +403,7 @@ public:
request<fail_body> m{verb::get, "/", 10, fc};
m.set(field::user_agent, "test");
m.set(field::transfer_encoding, "chunked");
m.body = "*****";
m.body() = "*****";
error_code ec = test::error::fail_error;
write(ts, m, ec);
if(ec == error::end_of_stream)
@@ -433,7 +433,7 @@ public:
request<fail_body> m{verb::get, "/", 10, fc};
m.set(field::user_agent, "test");
m.set(field::transfer_encoding, "chunked");
m.body = "*****";
m.body() = "*****";
error_code ec = test::error::fail_error;
async_write(ts, m, do_yield[ec]);
if(ec == error::end_of_stream)
@@ -464,7 +464,7 @@ public:
m.set(field::user_agent, "test");
m.set(field::connection, "keep-alive");
m.set(field::content_length, "5");
m.body = "*****";
m.body() = "*****";
error_code ec = test::error::fail_error;
write(ts, m, ec);
if(! ec)
@@ -491,7 +491,7 @@ public:
m.set(field::user_agent, "test");
m.set(field::connection, "keep-alive");
m.set(field::content_length, "5");
m.body = "*****";
m.body() = "*****";
error_code ec = test::error::fail_error;
async_write(ts, m, do_yield[ec]);
if(! ec)
@@ -520,7 +520,7 @@ public:
m.target("/");
m.version = 10;
m.set(field::user_agent, "test");
m.body = "*";
m.body() = "*";
m.prepare_payload();
BEAST_EXPECT(str(m) ==
"GET / HTTP/1.0\r\n"
@@ -537,7 +537,7 @@ public:
m.target("/");
m.version = 10;
m.set(field::user_agent, "test");
m.body = "*";
m.body() = "*";
m.prepare_payload();
test::stream ts{ios_}, tr{ios_};
ts.connect(tr);
@@ -558,7 +558,7 @@ public:
m.target("/");
m.version = 11;
m.set(field::user_agent, "test");
m.body = "*";
m.body() = "*";
m.prepare_payload();
BEAST_EXPECT(str(m) ==
"GET / HTTP/1.1\r\n"
@@ -575,7 +575,7 @@ public:
m.target("/");
m.version = 11;
m.set(field::user_agent, "test");
m.body = "*";
m.body() = "*";
m.prepare_payload();
test::stream ts{ios_}, tr{ios_};
ts.connect(tr);
@@ -601,7 +601,7 @@ public:
m.target("/");
m.version = 11;
m.set(field::user_agent, "test");
m.body = "*";
m.body() = "*";
BEAST_EXPECT(to_string(m) ==
"GET / HTTP/1.1\r\nUser-Agent: test\r\n\r\n*");
}
@@ -631,7 +631,7 @@ public:
m.version = 11;
m.target("/");
m.set("Content-Length", 5);
m.body = "*****";
m.body() = "*****";
async_write(ts, m, handler{});
BEAST_EXPECT(handler::count() > 0);
ios.stop();
@@ -654,7 +654,7 @@ public:
m.version = 11;
m.target("/");
m.set("Content-Length", 5);
m.body = "*****";
m.body() = "*****";
async_write(ts, m, handler{});
BEAST_EXPECT(handler::count() > 0);
}
@@ -716,7 +716,7 @@ public:
m0.result(status::ok);
m0.reason("OK");
m0.set(field::server, "test");
m0.body.s = "Hello, world!\n";
m0.body().s = "Hello, world!\n";
{
std::string const result =
@@ -730,7 +730,7 @@ public:
do_write(ts, m, ec);
BEAST_EXPECT(tr.str() == result);
BEAST_EXPECT(equal_body<false>(
tr.str(), m.body.s));
tr.str(), m.body().s));
tr.clear();
}
{
@@ -739,7 +739,7 @@ public:
do_async_write(ts, m, ec, yield);
BEAST_EXPECT(tr.str() == result);
BEAST_EXPECT(equal_body<false>(
tr.str(), m.body.s));
tr.str(), m.body().s));
tr.clear();
}
{
@@ -753,7 +753,7 @@ public:
if(sr.is_header_done())
break;
}
BEAST_EXPECT(! m.body.read);
BEAST_EXPECT(! m.body().read);
tr.clear();
}
{
@@ -767,7 +767,7 @@ public:
if(sr.is_header_done())
break;
}
BEAST_EXPECT(! m.body.read);
BEAST_EXPECT(! m.body().read);
tr.clear();
}
}
@@ -778,7 +778,7 @@ public:
error_code ec;
do_write(ts, m, ec);
BEAST_EXPECT(equal_body<false>(
tr.str(), m.body.s));
tr.str(), m.body().s));
tr.clear();
}
{
@@ -786,7 +786,7 @@ public:
error_code ec;
do_async_write(ts, m, ec, yield);
BEAST_EXPECT(equal_body<false>(
tr.str(), m.body.s));
tr.str(), m.body().s));
tr.clear();
}
{
@@ -800,7 +800,7 @@ public:
if(sr.is_header_done())
break;
}
BEAST_EXPECT(! m.body.read);
BEAST_EXPECT(! m.body().read);
tr.clear();
}
{
@@ -814,7 +814,7 @@ public:
if(sr.is_header_done())
break;
}
BEAST_EXPECT(! m.body.read);
BEAST_EXPECT(! m.body().read);
tr.clear();
}
}
+5 -5
View File
@@ -78,7 +78,7 @@ public:
try
{
read(ts, b, m);
return m.body == body;
return m.body() == body;
}
catch(std::exception const& e)
{
@@ -109,7 +109,7 @@ public:
req.method_string("POST");
req.target("/");
req.insert(field::user_agent, "test");
req.body = "Hello, world!";
req.body() = "Hello, world!";
req.prepare_payload();
error_code ec;
@@ -142,7 +142,7 @@ public:
req.method_string("POST");
req.target("/");
req.insert(field::user_agent, "test");
req.body = "Hello, world!";
req.body() = "Hello, world!";
req.prepare_payload();
test::stream ds{ios_}, dsr{ios_};
@@ -167,7 +167,7 @@ public:
});
BEAST_EXPECTS(! ec, ec.message());
BEAST_EXPECT(equal_body<true>(
usr.str(), req.body));
usr.str(), req.body()));
}
void
@@ -273,7 +273,7 @@ public:
void
operator()(request<string_body>&& req)
{
body = req.body;
body = req.body();
}
};
+2 -2
View File
@@ -61,7 +61,7 @@ void fxx() {
res.version = 11; // HTTP/1.1
res.result(status::ok);
res.set(field::server, "Beast");
res.body = "Hello, world!";
res.body() = "Hello, world!";
res.prepare_payload();
//]
@@ -115,7 +115,7 @@ void fxx() {
res.version = 11;
res.result(status::ok);
res.set(field::server, "Beast");
res.body = "Hello, world!";
res.body() = "Hello, world!";
error_code ec;
write(sock, res, ec);