From 5193382b074f1a31d9b262deec2351f7a7045a0b Mon Sep 17 00:00:00 2001 From: marinpostma Date: Thu, 14 May 2020 17:52:10 +0200 Subject: [PATCH] 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, }