Add basic_parser header and body limits:

fix #550

* default body limits are now 1MB/8MB
* default header limit is 8KB

Actions Required:

* Call body_limit and/or header_limit as needed to adjust the
  limits to suitable values if the defaults are insufficient.
This commit is contained in:
Vinnie Falco
2017-06-27 21:00:53 -07:00
parent 3c4ae2a098
commit 788550e833
8 changed files with 229 additions and 17 deletions

View File

@@ -615,7 +615,6 @@ public:
length(c("1\r\n"), 1);
length(c("01\r\n"), 1);
length(c("9\r\n"), 9);
length(c("123456789\r\n"), 123456789);
length(c("42 \r\n"), 42);
length(c("42\t\r\n"), 42);
length(c("42 \t \r\n"), 42);
@@ -923,6 +922,68 @@ public:
BEAST_EXPECT(p.body == "*****");
}
void
testLimits()
{
{
multi_buffer b;
ostream(b) <<
"POST / HTTP/1.1\r\n"
"Content-Length: 2\r\n"
"\r\n"
"**";
error_code ec;
test_parser<true> p;
p.header_limit(10);
p.eager(true);
p.put(b.data(), ec);
BEAST_EXPECTS(ec == error::header_limit, ec.message());
}
{
multi_buffer b;
ostream(b) <<
"POST / HTTP/1.1\r\n"
"Content-Length: 2\r\n"
"\r\n"
"**";
error_code ec;
test_parser<true> p;
p.body_limit(1);
p.eager(true);
p.put(b.data(), ec);
BEAST_EXPECTS(ec == error::body_limit, ec.message());
}
{
multi_buffer b;
ostream(b) <<
"HTTP/1.1 200 OK\r\n"
"\r\n"
"**";
error_code ec;
test_parser<false> p;
p.body_limit(1);
p.eager(true);
p.put(b.data(), ec);
BEAST_EXPECTS(ec == error::body_limit, ec.message());
}
{
multi_buffer b;
ostream(b) <<
"POST / HTTP/1.1\r\n"
"Transfer-Encoding: chunked\r\n"
"\r\n"
"2\r\n"
"**\r\n"
"0\r\n\r\n";
error_code ec;
test_parser<true> p;
p.body_limit(1);
p.eager(true);
p.put(b.data(), ec);
BEAST_EXPECTS(ec == error::body_limit, ec.message());
}
}
//--------------------------------------------------------------------------
template<bool isRequest, class Derived>
@@ -1088,6 +1149,7 @@ public:
testUpgradeField();
testBody();
testSplit();
testLimits();
testIssue430();
testIssue452();
testIssue496();