From d38bf4e386cf438c95fa2b68044d7be3d0c13833 Mon Sep 17 00:00:00 2001 From: David Bottiau Date: Thu, 6 Jun 2024 13:37:04 +0200 Subject: [PATCH] fix: handle content-type with charset (#4139) --- src/net/headers/accept.rs | 4 +++- src/net/headers/content_type.rs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/net/headers/accept.rs b/src/net/headers/accept.rs index 7191192f..b433d3c8 100644 --- a/src/net/headers/accept.rs +++ b/src/net/headers/accept.rs @@ -36,8 +36,10 @@ impl Header for Accept { I: Iterator, { let value = values.next().ok_or_else(headers::Error::invalid)?; + let parts: Vec<&str> = + value.to_str().map_err(|_| headers::Error::invalid())?.split(';').collect(); - match value.to_str().map_err(|_| headers::Error::invalid())? { + match parts[0] { "text/plain" => Ok(Accept::TextPlain), "application/json" => Ok(Accept::ApplicationJson), "application/cbor" => Ok(Accept::ApplicationCbor), diff --git a/src/net/headers/content_type.rs b/src/net/headers/content_type.rs index 9bff7b57..90183508 100644 --- a/src/net/headers/content_type.rs +++ b/src/net/headers/content_type.rs @@ -36,8 +36,10 @@ impl Header for ContentType { I: Iterator, { let value = values.next().ok_or_else(headers::Error::invalid)?; + let parts: Vec<&str> = + value.to_str().map_err(|_| headers::Error::invalid())?.split(';').collect(); - match value.to_str().map_err(|_| headers::Error::invalid())? { + match parts[0] { "text/plain" => Ok(ContentType::TextPlain), "application/json" => Ok(ContentType::ApplicationJson), "application/cbor" => Ok(ContentType::ApplicationCbor),