add missing content type errors

This commit is contained in:
mpostma 2021-09-29 00:19:08 +02:00
parent 911630000f
commit 5bac65f8b8

View File

@ -32,9 +32,14 @@ macro_rules! guard_content_type {
} }
}; };
} }
guard_content_type!(guard_json, "application/json"); guard_content_type!(guard_json, "application/json");
guard_content_type!(guard_csv, "application/csv"); 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 /// This is required because Payload is not Sync nor Send
fn payload_to_stream(mut payload: Payload) -> impl Stream<Item = Result<Bytes, PayloadError>> { fn payload_to_stream(mut payload: Payload) -> impl Stream<Item = Result<Bytes, PayloadError>> {
let (snd, recv) = mpsc::channel(1); let (snd, recv) = mpsc::channel(1);
@ -56,10 +61,16 @@ pub fn configure(cfg: &mut web::ServiceConfig) {
cfg.service( cfg.service(
web::resource("") web::resource("")
.route(web::get().to(get_all_documents)) .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_json).to(add_documents_json))
.route(web::post().guard(guard_csv).to(add_documents_csv)) .route(web::post().guard(guard_csv).to(add_documents_csv))
.route(web::post().guard(guard_json).to(update_documents_json)) .route(web::post().to(|| HttpResponse::UnsupportedMediaType()))
.route(web::post().guard(guard_csv).to(update_documents_csv))
.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)), .route(web::delete().to(clear_all_documents)),
) )
// this route needs to be before the /documents/{document_id} to match properly // this route needs to be before the /documents/{document_id} to match properly