client: fix content type parsing with included charset

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2023-08-25 08:36:19 +02:00
parent 1f351625a5
commit d7f6fc4db5

View File

@ -82,20 +82,20 @@ impl HttpApiResponse {
} }
fn assert_json_content_type(&self) -> Result<(), Error> { fn assert_json_content_type(&self) -> Result<(), Error> {
match self.content_type.as_deref() { match self
.content_type
.as_deref()
.and_then(|v| v.split(';').next())
{
Some("application/json") => Ok(()), Some("application/json") => Ok(()),
Some(other) => { Some(other) => Err(Error::BadApi(
Err(Error::BadApi( format!("expected json body, got {other}",),
format!("expected json body, got {other}",), None,
None, )),
)) None => Err(Error::BadApi(
} "expected json body, but no Content-Type was sent".to_string(),
None => { None,
Err(Error::BadApi( )),
"expected json body, but no Content-Type was sent".to_string(),
None,
))
}
} }
} }