diff --git a/include/boost/beast/http/parser.hpp b/include/boost/beast/http/parser.hpp index 4851fe8f..a5b93d17 100644 --- a/include/boost/beast/http/parser.hpp +++ b/include/boost/beast/http/parser.hpp @@ -430,9 +430,9 @@ private: 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 diff --git a/test/beast/http/parser.cpp b/test/beast/http/parser.cpp index e6829e2d..3d26576b 100644 --- a/test/beast/http/parser.cpp +++ b/test/beast/http/parser.cpp @@ -326,6 +326,40 @@ public: 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 p; + p.header_limit((std::numeric_limits::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 p; + p.header_limit((std::numeric_limits::max)()); + error_code ec; + flat_buffer b; + ostream(b) << + "HTTP/1.1 200 OK\r\n" + << "name: " + << big_field_value << "\r\n" + << "\r\n"; + put(b.data(), p, ec); + BEAST_EXPECT(ec == error::header_field_value_too_large); + } + } + void testIssue818() { @@ -457,6 +491,7 @@ public: testParse(); testNeedMore(); testNeedMore(); + testHeaderFieldLimits(); testGotSome(); testIssue818(); testIssue1187();