Repository: meilisearch/meilisearch
File: meilisearch-http/src/routes/indexes/documents.rs (Rust)

Code before:
    primary_key: Option<String>,
    body: Payload,
    method: IndexDocumentsMethod,
) -> Result<HttpResponse, ResponseError> {
    let format = match content_type {
        Some("application/json") => DocumentAdditionFormat::Json,
        Some("application/x-ndjson") => DocumentAdditionFormat::Ndjson,
        Some("text/csv") => DocumentAdditionFormat::Csv,
        Some(other) => {
            return Err(MeilisearchHttpError::InvalidContentType(
                other.to_string(),
                vec![
                    "application/json".to_string(),
                    "application/x-ndjson".to_string(),
                    "application/csv".to_string(),
                ],
            )
            .into())
        }
        None => {
            return Err(MeilisearchHttpError::MissingContentType(vec![
                "application/json".to_string(),
                "application/x-ndjson".to_string(),
                "application/csv".to_string(),
            ])
            .into())
        }
    };

    let update = Update::DocumentAddition {
        payload: Box::new(payload_to_stream(body)),
        primary_key,
        method,
        format,
    };

    let update_status = meilisearch.register_update(index_uid, update, true).await?;

    debug!("returns: {:?}", update_status);
    Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
}

pub async fn delete_documents(
    meilisearch: GuardedData<Private, MeiliSearch>,
    path: web::Path<IndexParam>,
    body: web::Json<Vec<Value>>,
) -> Result<HttpResponse, ResponseError> {
    debug!("called with params: {:?}", body);
    let ids = body
        .iter()
        .map(|v| {

Review comment (suggestion):
make it a const instead:
```const aACCEPTED_CONTENT_TYPE = [
                "application/json".to_string(),
                "application/x-ndjson".to_string(),
                "application/csv".to_string(),
            ];

// ... later
 return Err(MeilisearchHttpError::MissingContentType(ACCEPTED_CONTENT_TYPE.clone()))

Code after:
    index_uid: String,
    primary_key: Option<String>,
    body: Payload,
    method: IndexDocumentsMethod,
) -> Result<HttpResponse, ResponseError> {
    static ACCEPTED_CONTENT_TYPE: Lazy<Vec<String>> = Lazy::new(|| {
        vec![
            "application/json".to_string(),
            "application/x-ndjson".to_string(),
            "application/csv".to_string(),
        ]
    });
    let format = match content_type {
        Some("application/json") => DocumentAdditionFormat::Json,
        Some("application/x-ndjson") => DocumentAdditionFormat::Ndjson,
        Some("text/csv") => DocumentAdditionFormat::Csv,
        Some(other) => {
            return Err(MeilisearchHttpError::InvalidContentType(
                other.to_string(),
                ACCEPTED_CONTENT_TYPE.clone(),
            )
            .into())
        }
        None => {
            return Err(
                MeilisearchHttpError::MissingContentType(ACCEPTED_CONTENT_TYPE.clone()).into(),
            )
        }
    };

    let update = Update::DocumentAddition {
        payload: Box::new(payload_to_stream(body)),
        primary_key,
        method,
        format,
    };

    let update_status = meilisearch.register_update(index_uid, update, true).await?;

    debug!("returns: {:?}", update_status);
    Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() })))
}

pub async fn delete_documents(
    meilisearch: GuardedData<Private, MeiliSearch>,
    path: web::Path<IndexParam>,
    body: web::Json<Vec<Value>>,
) -> Result<HttpResponse, ResponseError> {
    debug!("called with params: {:?}", body);
    let ids = body
        .iter()