From 5193382b074f1a31d9b262deec2351f7a7045a0b Mon Sep 17 00:00:00 2001 From: marinpostma Date: Thu, 14 May 2020 17:52:10 +0200 Subject: [PATCH 1/3] allow max payload size override --- meilisearch-http/src/data.rs | 4 ++++ meilisearch-http/src/lib.rs | 2 +- meilisearch-http/src/option.rs | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/meilisearch-http/src/data.rs b/meilisearch-http/src/data.rs index 056efe73d..8a6cd08a3 100644 --- a/meilisearch-http/src/data.rs +++ b/meilisearch-http/src/data.rs @@ -35,6 +35,7 @@ pub struct DataInner { pub db_path: String, pub api_keys: ApiKeys, pub server_pid: Pid, + pub http_payload_size_limit: usize, } #[derive(Clone)] @@ -137,6 +138,8 @@ impl Data { update_map_size: opt.update_map_size, }; + let http_payload_size_limit = opt.http_payload_size_limit; + let db = Arc::new(Database::open_or_create(opt.db_path, db_opt).unwrap()); let mut api_keys = ApiKeys { @@ -152,6 +155,7 @@ impl Data { db_path, api_keys, server_pid, + http_payload_size_limit, }; let data = Data { diff --git a/meilisearch-http/src/lib.rs b/meilisearch-http/src/lib.rs index 465f96caa..e2e24d4d2 100644 --- a/meilisearch-http/src/lib.rs +++ b/meilisearch-http/src/lib.rs @@ -31,7 +31,7 @@ pub fn create_app( .app_data(web::Data::new(data.clone())) .app_data( web::JsonConfig::default() - .limit(1024 * 1024 * 10) // Json Limit of 10Mb + .limit(data.http_payload_size_limit) .content_type(|_mime| true) // Accept all mime types .error_handler(|err, _req| json_error_handler(err).into()), ) diff --git a/meilisearch-http/src/option.rs b/meilisearch-http/src/option.rs index d9fe3599c..2746b907c 100644 --- a/meilisearch-http/src/option.rs +++ b/meilisearch-http/src/option.rs @@ -34,4 +34,8 @@ pub struct Opt { /// The maximum size, in bytes, of the update lmdb database directory #[structopt(long, env = "MEILI_UPDATE_MAP_SIZE", default_value = "107374182400")] // 100GB pub update_map_size: usize, + + /// The maximum size, in bytes, of accepted JSON payloads + #[structopt(long, env = "MEILI_HTTP_PAYLOAD_SIZE_LIMIT", default_value = "10485760")] // 10MB + pub http_payload_size_limit: usize, } From df2eed1be3012c3b34be949eb355b1afb14f9c48 Mon Sep 17 00:00:00 2001 From: marinpostma Date: Thu, 14 May 2020 18:00:27 +0200 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffcaca57c..fc2ab14f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## v0.10.2 - Bump sentry version to 0.18.1 (#690) + - Enable max payload size override (#684) - Disable sentry in debug (#681) - Better terminal greeting (#680) - Fix highlight misalignment (#679) From c5daa4a25614b2ae468493e7470bd6c74266e9d0 Mon Sep 17 00:00:00 2001 From: mpostma Date: Fri, 15 May 2020 11:03:29 +0200 Subject: [PATCH 3/3] fix tests --- meilisearch-http/tests/common.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/meilisearch-http/tests/common.rs b/meilisearch-http/tests/common.rs index 3b9ac8c2e..b8401f58b 100644 --- a/meilisearch-http/tests/common.rs +++ b/meilisearch-http/tests/common.rs @@ -30,6 +30,7 @@ impl Server { no_analytics: true, main_map_size: default_db_options.main_map_size, update_map_size: default_db_options.update_map_size, + http_payload_size_limit: 10000000, }; let data = Data::new(opt.clone());