HTTP Reader (API Change):

fix #114, fix #117, fix #136

* Added init() to Reader requirements
* Reader must be nothrow constructible
* Reader is now constructed right before reading the body
  - The message passed on construction is filled in
This commit is contained in:
Vinnie Falco
2017-07-20 08:12:13 -07:00
parent 35d1ee54bc
commit f110e51dd1
8 changed files with 171 additions and 55 deletions
+70 -1
View File
@@ -26,8 +26,63 @@ class read_test
, public test::enable_yield_to
{
public:
struct fail_body
{
class reader;
class value_type
{
friend class reader;
std::string s_;
test::fail_counter& fc_;
public:
explicit
value_type(test::fail_counter& fc)
: fc_(fc)
{
}
value_type&
operator=(std::string s)
{
s_ = std::move(s);
return *this;
}
};
class reader
{
std::size_t n_ = 0;
value_type& body_;
public:
template<bool isRequest, class Allocator>
explicit
reader(message<isRequest, fail_body, Allocator>& msg) noexcept
: body_(msg.body)
{
}
void
init(error_code& ec) noexcept
{
body_.fc_.fail(ec);
}
void
write(void const* data,
std::size_t size, error_code& ec) noexcept
{
if(body_.fc_.fail(ec))
return;
}
};
};
template<bool isRequest>
void failMatrix(const char* s, yield_context do_yield)
void failMatrix(char const* s, yield_context do_yield)
{
using boost::asio::buffer;
using boost::asio::buffer_copy;
@@ -96,6 +151,20 @@ public:
break;
}
BEAST_EXPECT(n < limit);
for(n = 0; n < limit; ++n)
{
streambuf sb;
sb.commit(buffer_copy(
sb.prepare(len), buffer(s, len)));
test::fail_counter fc{n};
test::string_stream ss{ios_, s};
parser_v1<isRequest, fail_body, headers> p{fc};
error_code ec;
parse(ss, sb, p, ec);
if(! ec)
break;
}
BEAST_EXPECT(n < limit);
}
void testThrow()