fix: handle content-type with charset (#4139)
This commit is contained in:
parent
9c196fa154
commit
d38bf4e386
2 changed files with 6 additions and 2 deletions
|
@ -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),
|
||||||
|
|
|
@ -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),
|
||||||
|
|
Loading…
Reference in a new issue