Skip to content

Commit

Permalink
rpc: override max HTTP request body limit (#1934)
Browse files Browse the repository at this point in the history
  • Loading branch information
canepat authored Mar 25, 2024
1 parent 50dc812 commit a8ce342
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions silkworm/rpc/http/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ Task<bool> Connection::do_read() {
SILK_TRACE << "Connection::do_read going to read...";

boost::beast::http::request_parser<boost::beast::http::string_body> parser;
auto bytes_transferred = co_await boost::beast::http::async_read(socket_, data_, parser, boost::asio::use_awaitable);
parser.body_limit(kMaxPayloadSize);

SILK_TRACE << "Connection::do_read bytes_read: " << bytes_transferred << " [" << parser.get() << "]";
const auto bytes_transferred = co_await boost::beast::http::async_read(socket_, data_, parser, boost::asio::use_awaitable);
SILK_TRACE << "Connection::do_read bytes_read: " << bytes_transferred << " message: " << parser.get();

if (!parser.is_done()) {
co_return true;
Expand Down Expand Up @@ -185,14 +186,11 @@ Task<void> Connection::handle_actual_request(const boost::beast::http::request<b
co_return;
}

// Check HTTP method and content type [max body size is limited using beast::http::request_parser::body_limit in do_read]
if (!is_method_allowed(req.method())) {
co_await do_write("method not allowed\n", boost::beast::http::status::method_not_allowed);
co_return;
}
if (req.has_content_length() && req.body().length() > kMaxPayloadSize) {
co_await do_write("content length too large\n", boost::beast::http::status::payload_too_large);
co_return;
}
if (req.method() != boost::beast::http::verb::options && req.method() != boost::beast::http::verb::get) {
if (!is_accepted_content_type(req[boost::beast::http::field::content_type])) {
co_await do_write("invalid content type\n, only application/json is supported\n", boost::beast::http::status::bad_request);
Expand Down

0 comments on commit a8ce342

Please sign in to comment.