Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the request body limit configurable (and increase the default) #1762

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions src/ServerMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ int main(int argc, char** argv) {
"variables that are unbound in the query throw an exception. These "
"queries technically are allowed by the SPARQL standard, but typically "
"are the result of typos and unintended by the user");
add("request-body-limit",
optionFactory.getProgramOption<"request-body-limit">(),
"Set the maximum size for the body of requests the server will process. "
"Set to zero to disable the limit.");
po::variables_map optionsMap;

try {
Expand Down
2 changes: 2 additions & 0 deletions src/global/RuntimeParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ inline auto& RuntimeParameters() {
// Determines whether the cost estimate for a cached subtree should be
// set to zero in query planning.
Bool<"zero-cost-estimate-for-cached-subtree">{false},
// Maximum size for the body of requests that the server will process.
MemorySizeParameter<"request-body-limit">{1_MB},
};
}();
return params;
Expand Down
14 changes: 11 additions & 3 deletions src/util/http/HttpServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <future>

#include "absl/cleanup/cleanup.h"
#include "global/RuntimeParameters.h"
#include "util/Exception.h"
#include "util/Log.h"
#include "util/http/HttpUtils.h"
Expand Down Expand Up @@ -245,11 +246,18 @@ CPP_template(typename HttpHandler, typename WebSocketHandler)(
try {
// Set the timeout for reading the next request.
stream.expires_after(std::chrono::seconds(30));
http::request<http::string_body> req;

// Read a request
co_await http::async_read(stream, buffer, req,
// Read a request. Use a parser so that we can control the limit of the
// request size.
http::request_parser<http::string_body> requestParser;
auto bodyLimit =
RuntimeParameters().get<"request-body-limit">().getBytes();
requestParser.body_limit(bodyLimit == 0
? boost::none
: boost::optional<uint64_t>(bodyLimit));
co_await http::async_read(stream, buffer, requestParser,
boost::asio::use_awaitable);
http::request<http::string_body> req = requestParser.release();

// Let request be handled by `WebSocketSession` if the HTTP
// request is a WebSocket handshake
Expand Down
Loading