Skip to content

Commit

Permalink
basic_parser: set state_ before calling on_finish_impl
Browse files Browse the repository at this point in the history
  • Loading branch information
ashtum committed Aug 21, 2024
1 parent a620d41 commit b1f377b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
22 changes: 4 additions & 18 deletions include/boost/beast/http/impl/basic_parser.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,11 @@ loop:

case state::trailer_fields:
parse_fields(p, n, ec);
if(ec)
goto done;
this->on_finish_impl(ec);
if(ec)
goto done;
state_ = state::complete;
break;
this->on_finish_impl(ec);
goto done;

case state::chunk_body:
parse_chunk_body(p, n, ec);
Expand Down Expand Up @@ -221,11 +219,9 @@ put_eof(error_code& ec)
ec = {};
return;
}
state_ = state::complete;
ec = {};
this->on_finish_impl(ec);
if(ec)
return;
state_ = state::complete;
}

template<bool isRequest>
Expand Down Expand Up @@ -464,11 +460,7 @@ finish_header(error_code& ec, std::true_type)
if(ec)
return;
if(state_ == state::complete)
{
this->on_finish_impl(ec);
if(ec)
return;
}
}

template<bool isRequest>
Expand Down Expand Up @@ -525,11 +517,7 @@ finish_header(error_code& ec, std::false_type)
if(ec)
return;
if(state_ == state::complete)
{
this->on_finish_impl(ec);
if(ec)
return;
}
}

template<bool isRequest>
Expand All @@ -547,10 +535,8 @@ parse_body(char const*& p,
return;
if(len_ > 0)
return;
this->on_finish_impl(ec);
if(ec)
return;
state_ = state::complete;
this->on_finish_impl(ec);
}

template<bool isRequest>
Expand Down
24 changes: 24 additions & 0 deletions test/beast/http/basic_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,18 @@ class basic_parser_test : public beast::unit_test::suite
void
testCallbacks()
{
parsegrind<test_parser<true>>(
"GET / HTTP/1.1\r\n"
"\r\n",
[&](test_parser<true> const& p)
{
BEAST_EXPECT(p.got_on_begin == 1);
BEAST_EXPECT(p.got_on_field == 0);
BEAST_EXPECT(p.got_on_header == 1);
BEAST_EXPECT(p.got_on_body == 0);
BEAST_EXPECT(p.got_on_chunk == 0);
BEAST_EXPECT(p.got_on_complete == 1);
});
parsegrind<test_parser<true>>(
"GET / HTTP/1.1\r\n"
"User-Agent: test\r\n"
Expand All @@ -378,6 +390,18 @@ class basic_parser_test : public beast::unit_test::suite
BEAST_EXPECT(p.got_on_chunk == 0);
BEAST_EXPECT(p.got_on_complete == 1);
});
parsegrind<test_parser<false>>(
"HTTP/1.1 100 Continue\r\n"
"\r\n",
[&](test_parser<false> const& p)
{
BEAST_EXPECT(p.got_on_begin == 1);
BEAST_EXPECT(p.got_on_field == 0);
BEAST_EXPECT(p.got_on_header == 1);
BEAST_EXPECT(p.got_on_body == 0);
BEAST_EXPECT(p.got_on_chunk == 0);
BEAST_EXPECT(p.got_on_complete == 1);
});
parsegrind<test_parser<false>>(
"HTTP/1.1 200 OK\r\n"
"Server: test\r\n"
Expand Down

0 comments on commit b1f377b

Please sign in to comment.