fix: handle content-type with charset (#4139)

This commit is contained in:
David Bottiau 2024-06-06 13:37:04 +02:00 committed by GitHub
parent 9c196fa154
commit d38bf4e386
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View file

@ -36,8 +36,10 @@ impl Header for Accept {
I: Iterator<Item = &'i HeaderValue>, I: Iterator<Item = &'i HeaderValue>,
{ {
let value = values.next().ok_or_else(headers::Error::invalid)?; 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), "text/plain" => Ok(Accept::TextPlain),
"application/json" => Ok(Accept::ApplicationJson), "application/json" => Ok(Accept::ApplicationJson),
"application/cbor" => Ok(Accept::ApplicationCbor), "application/cbor" => Ok(Accept::ApplicationCbor),

View file

@ -36,8 +36,10 @@ impl Header for ContentType {
I: Iterator<Item = &'i HeaderValue>, I: Iterator<Item = &'i HeaderValue>,
{ {
let value = values.next().ok_or_else(headers::Error::invalid)?; 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), "text/plain" => Ok(ContentType::TextPlain),
"application/json" => Ok(ContentType::ApplicationJson), "application/json" => Ok(ContentType::ApplicationJson),
"application/cbor" => Ok(ContentType::ApplicationCbor), "application/cbor" => Ok(ContentType::ApplicationCbor),