Skip to content

Commit

Permalink
[FOLD] parser, test tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
vinniefalco committed Dec 23, 2023
1 parent f15581c commit 1bf649d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 82 deletions.
50 changes: 13 additions & 37 deletions include/boost/http_proto/impl/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,22 @@ namespace http_proto {
template<class ElasticBuffer>
typename std::enable_if<
! detail::is_reference_wrapper<
ElasticBuffer>::value>::type
ElasticBuffer>::value &&
! is_sink<ElasticBuffer>::value>::type
parser::
set_body_(
set_body(
ElasticBuffer&& eb)
{
// If this goes off it means you are trying
// to pass by lvalue reference. Use std::ref
// instead.
static_assert(
! std::is_reference<ElasticBuffer>::value,
"Use std::ref instead of pass-by-reference");

// Check ElasticBuffer type requirements
static_assert(
buffers::is_dynamic_buffer<ElasticBuffer>,
buffers::is_dynamic_buffer<ElasticBuffer>::value,
"Type requirements not met.");

// body must not be set already
Expand All @@ -51,12 +59,12 @@ set_body_(
template<class ElasticBuffer>
void
parser::
set_body_(
set_body(
std::reference_wrapper<ElasticBuffer> eb)
{
// Check ElasticBuffer type requirements
static_assert(
buffers::is_dynamic_buffer<ElasticBuffer>,
buffers::is_dynamic_buffer<ElasticBuffer>::value,
"Type requirements not met.");

// body must not be set already
Expand All @@ -76,38 +84,6 @@ set_body_(
on_set_body();
}

//------------------------------------------------

template<class DynamicBuffer, class>
typename std::decay<
DynamicBuffer>::type&
parser::
set_body(
DynamicBuffer&& b)
{
// body must not be set already
if(how_ != how::in_place)
detail::throw_logic_error();

// headers must be complete
if(! got_header())
detail::throw_logic_error();

auto& dyn = ws_.push(
buffers::any_dynamic_buffer_impl<typename
std::decay<DynamicBuffer>::type,
buffers_N>(std::forward<
DynamicBuffer>(b)));
dyn_ = &dyn;
how_ = how::dynamic;
on_set_body();
return dyn.buffer();
}

//------------------------------------------------



//------------------------------------------------

template<class Sink>
Expand Down
29 changes: 6 additions & 23 deletions include/boost/http_proto/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,25 +266,6 @@ class BOOST_SYMBOL_VISIBLE
parse(
system::error_code& ec);

/** Attach a body
*/
// VFALCO Should this function have
// error_code& ec and call parse?
#ifndef BOOST_HTTP_PROTO_DOCS
template<
class DynamicBuffer
, class = typename std::enable_if<
buffers::is_dynamic_buffer<
DynamicBuffer>::value
>::type
>
#else
template<class DynamicBuffer>
#endif
typename std::decay<
DynamicBuffer>::type&
set_body(DynamicBuffer&& b);

/** Attach a body.
This function attaches the specified elastic
Expand All @@ -297,16 +278,18 @@ class BOOST_SYMBOL_VISIBLE
@li an unrecoverable parsing error occurs, or
@li the parser is destroyed.
*/
// VFALCO Should this function have
// error_code& ec and call parse?
template<class ElasticBuffer>
#ifndef BOOST_HTTP_PROTO_DOCS
typename std::enable_if<
! detail::is_reference_wrapper<
ElasticBuffer>::value>::type
ElasticBuffer>::value &&
! is_sink<ElasticBuffer>::value>::type
#else
void
#endif
set_body_(
ElasticBuffer&& eb);
set_body(ElasticBuffer&& eb);

/** Attach a body.
Expand All @@ -322,7 +305,7 @@ class BOOST_SYMBOL_VISIBLE
@li the parser is destroyed.
*/
template<class ElasticBuffer>
void set_body_(
void set_body(
std::reference_wrapper<ElasticBuffer> eb);

/** Attach a body
Expand Down
27 changes: 5 additions & 22 deletions test/unit/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,6 @@ This all speaks to DynamicBuffer as the correct API
*/
//------------------------------------------------

#if 0
// a buffer-oriented destination for bodies
struct parser::body
{
};

// a push-based destination for bodies
struct parser::sink
{
/** Called to set the content length when known.
*/
virtual result<void> content_length( std::uint64_t content_length );
};
#endif

namespace boost {
namespace http_proto {

Expand Down Expand Up @@ -668,12 +653,11 @@ struct parser_test
// requires small string optimization
BOOST_TEST_GT(s.capacity(), 0);
BOOST_TEST_LT(s.capacity(), 5000);
auto& body = pr.set_body(
buffers::string_buffer(&s));
pr.set_body(buffers::string_buffer(&s));
auto dest = pr.prepare();
BOOST_TEST_EQ(
BOOST_TEST_LE(
buffers::buffer_size(dest),
body.capacity());
s.capacity());
}

{
Expand Down Expand Up @@ -1264,9 +1248,8 @@ struct parser_test
BOOST_TEST_EQ(ec, ex);
return;
}
auto& fb = pr_->set_body(
buffers::flat_buffer(
buf, sizeof(buf)));
buffers::flat_buffer fb(buf, sizeof(buf));
pr_->set_body(std::ref(fb));
BOOST_TEST(pr_->body().empty());
if(! pr_->is_complete())
{
Expand Down

0 comments on commit 1bf649d

Please sign in to comment.