accept no content-type as json

This commit is contained in:
Tamo 2021-06-29 11:57:47 +02:00
parent f12ace3fbf
commit 1dc99ea451
No known key found for this signature in database
GPG key ID: 20CD8020AFA88D69
2 changed files with 93 additions and 1 deletions

View file

@ -13,6 +13,7 @@ use crate::Data;
const DEFAULT_RETRIEVE_DOCUMENTS_OFFSET: usize = 0;
const DEFAULT_RETRIEVE_DOCUMENTS_LIMIT: usize = 20;
/*
macro_rules! guard_content_type {
($fn_name:ident, $guard_value:literal) => {
fn $fn_name(head: &actix_web::dev::RequestHead) -> bool {
@ -29,6 +30,19 @@ macro_rules! guard_content_type {
}
guard_content_type!(guard_json, "application/json");
*/
fn guard_json(head: &actix_web::dev::RequestHead) -> bool {
if let Some(content_type) = head.headers.get("Content-Type") {
content_type
.to_str()
.map(|v| v.contains("application/json"))
// if no content-type is specified we still accept the data as json!
.unwrap_or(true)
} else {
false
}
}
#[derive(Deserialize)]
struct DocumentParam {
@ -146,6 +160,8 @@ async fn add_documents(
Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
}
/// Route used when the payload type is "application/json"
/// Used to add or replace documents
async fn update_documents(
data: GuardedData<Private, Data>,
path: web::Path<IndexParam>,