Skip to content

Commit

Permalink
parser uses basic_fields::insert() with error_code overload
Browse files Browse the repository at this point in the history
  • Loading branch information
ashtum committed Aug 17, 2024
1 parent 775a451 commit 4d66b54
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/boost/beast/http/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,9 @@ class parser
field name,
string_view name_string,
string_view value,
error_code&) override
error_code& ec) override
{
m_.insert(name, name_string, value);
m_.insert(name, name_string, value, ec);
}

void
Expand Down
36 changes: 36 additions & 0 deletions test/beast/http/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <boost/beast/http/string_body.hpp>
#include <boost/system/system_error.hpp>
#include <algorithm>
#include <iostream>

namespace boost {
namespace beast {
Expand Down Expand Up @@ -326,6 +327,40 @@ class parser_test
BEAST_EXPECT(used == 0);
}

void
testHeaderFieldLimits()
{
auto big_field_name = std::string(fields::max_name_size + 1, 'a');
auto big_field_value = std::string(fields::max_value_size + 1, 'a');

{
parser_type<false> p;
p.header_limit((std::numeric_limits<std::uint32_t>::max)());
error_code ec;
flat_buffer b;
ostream(b) <<
"HTTP/1.1 200 OK\r\n"
<< big_field_name
<<": value\r\n"
"\r\n";
put(b.data(), p, ec);
BEAST_EXPECT(ec == error::header_field_name_too_large);
}
{
parser_type<false> p;
p.header_limit((std::numeric_limits<std::uint32_t>::max)());
error_code ec;
flat_buffer b;
ostream(b) <<
"HTTP/1.1 200 OK\r\n"
<< "field: "
<< big_field_value << "\r\n"
<< "\r\n";
put(b.data(), p, ec);
BEAST_EXPECT(ec == error::header_field_value_too_large);
}
}

void
testIssue818()
{
Expand Down Expand Up @@ -457,6 +492,7 @@ class parser_test
testParse();
testNeedMore<flat_buffer>();
testNeedMore<multi_buffer>();
testHeaderFieldLimits();
testGotSome();
testIssue818();
testIssue1187();
Expand Down

0 comments on commit 4d66b54

Please sign in to comment.