diff --git a/alternator-test/test_large_requests.py b/alternator-test/test_large_requests.py index 0b21533e6f..b9f626404a 100644 --- a/alternator-test/test_large_requests.py +++ b/alternator-test/test_large_requests.py @@ -19,7 +19,7 @@ import pytest import requests -from botocore.exceptions import ClientError +from botocore.exceptions import BotoCoreError, ClientError def gen_json(n): return '{"":'*n + '{}' + '}'*n @@ -78,3 +78,13 @@ def test_exceed_nested_level_a_little(dynamodb, test_table): with pytest.raises(ClientError, match='ValidationException.*nested'): test_table.put_item(Item={'p': p, 'c': c, 'nested': nested}) + +def test_too_large_request(dynamodb, test_table): + p = 'abc' + c = 'def' + big = 'x' * (16 * 1024 * 1024 + 7) + # The exception type differs due to differences between HTTP servers + # in alternator and DynamoDB. The former returns 413, the latter + # a ClientError explaining that the element size was too large. + with pytest.raises(BotoCoreError): + test_table.put_item(Item={'p': p, 'c': c, 'big': big}) diff --git a/alternator/server.cc b/alternator/server.cc index ec62fc99f7..a858af88f6 100644 --- a/alternator/server.cc +++ b/alternator/server.cc @@ -358,6 +358,9 @@ future<> server::init(net::inet_address addr, std::optional port, std: _control.start().get(); _control.set_routes(std::bind(&server::set_routes, this, std::placeholders::_1)).get(); _control.listen(socket_address{addr, *port}).get(); + _control.server().invoke_on_all([] (http_server& serv) { + serv.set_content_length_limit(server::content_length_limit); + }).get(); _enabled_servers.push_back(std::ref(_control)); slogger.info("Alternator HTTP server listening on {} port {}", addr, *port); } @@ -365,6 +368,7 @@ future<> server::init(net::inet_address addr, std::optional port, std: _https_control.start().get(); _https_control.set_routes(std::bind(&server::set_routes, this, std::placeholders::_1)).get(); _https_control.server().invoke_on_all([creds] (http_server& serv) { + serv.set_content_length_limit(server::content_length_limit); return serv.set_tls_credentials(creds->build_server_credentials()); }).get(); diff --git a/alternator/server.hh b/alternator/server.hh index dc335bb8ee..c52fca61f6 100644 --- a/alternator/server.hh +++ b/alternator/server.hh @@ -28,10 +28,12 @@ #include #include #include +#include namespace alternator { class server { + static constexpr size_t content_length_limit = 16*MB; using alternator_callback = std::function(executor&, executor::client_state&, tracing::trace_state_ptr, std::unique_ptr)>; using alternator_callbacks_map = std::unordered_map;