From 5bac65f8b81b7ce189a358aff95580f99f84acc9 Mon Sep 17 00:00:00 2001 From: mpostma Date: Wed, 29 Sep 2021 00:19:08 +0200 Subject: [PATCH] add missing content type errors --- meilisearch-http/src/routes/indexes/documents.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/meilisearch-http/src/routes/indexes/documents.rs b/meilisearch-http/src/routes/indexes/documents.rs index dfa1244d1..ae66d439d 100644 --- a/meilisearch-http/src/routes/indexes/documents.rs +++ b/meilisearch-http/src/routes/indexes/documents.rs @@ -32,9 +32,14 @@ macro_rules! guard_content_type { } }; } + guard_content_type!(guard_json, "application/json"); guard_content_type!(guard_csv, "application/csv"); +fn empty_application_type(head: &actix_web::dev::RequestHead) -> bool { + head.headers.get("Content-Type").is_none() +} + /// This is required because Payload is not Sync nor Send fn payload_to_stream(mut payload: Payload) -> impl Stream> { let (snd, recv) = mpsc::channel(1); @@ -56,10 +61,16 @@ pub fn configure(cfg: &mut web::ServiceConfig) { cfg.service( web::resource("") .route(web::get().to(get_all_documents)) + + .route(web::post().guard(empty_application_type).to(|| HttpResponse::UnsupportedMediaType())) .route(web::post().guard(guard_json).to(add_documents_json)) .route(web::post().guard(guard_csv).to(add_documents_csv)) - .route(web::post().guard(guard_json).to(update_documents_json)) - .route(web::post().guard(guard_csv).to(update_documents_csv)) + .route(web::post().to(|| HttpResponse::UnsupportedMediaType())) + + .route(web::put().guard(empty_application_type).to(|| HttpResponse::UnsupportedMediaType())) + .route(web::put().guard(guard_json).to(update_documents_json)) + .route(web::put().guard(guard_csv).to(update_documents_csv)) + .route(web::put().to(|| HttpResponse::UnsupportedMediaType())) .route(web::delete().to(clear_all_documents)), ) // this route needs to be before the /documents/{document_id} to match properly