1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-11-21 23:00:50 +03:00

Use headers API

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
This commit is contained in:
Kévin Commaille
2024-05-30 10:02:55 +02:00
committed by Quentin Gliech
parent 683516bb66
commit fa0dec737b
2 changed files with 7 additions and 7 deletions

View File

@@ -452,8 +452,8 @@ pub enum UserInfoError {
DecodeResponseContentType(#[from] ToStrError), DecodeResponseContentType(#[from] ToStrError),
/// The content-type is not valid. /// The content-type is not valid.
#[error("invalid response content-type: {0}")] #[error("invalid response content-type")]
InvalidResponseContentTypeValue(#[from] mime::FromStrError), InvalidResponseContentTypeValue,
/// The content-type is not the one that was expected. /// The content-type is not the one that was expected.
#[error("unexpected response content-type {got:?}, expected {expected:?}")] #[error("unexpected response content-type {got:?}, expected {expected:?}")]

View File

@@ -19,8 +19,8 @@
use std::collections::HashMap; use std::collections::HashMap;
use bytes::Bytes; use bytes::Bytes;
use headers::{Authorization, HeaderMapExt, HeaderValue}; use headers::{Authorization, ContentType, HeaderMapExt, HeaderValue};
use http::header::{ACCEPT, CONTENT_TYPE}; use http::header::ACCEPT;
use mas_http::CatchHttpCodesLayer; use mas_http::CatchHttpCodesLayer;
use mas_jose::claims; use mas_jose::claims;
use mime::Mime; use mime::Mime;
@@ -101,10 +101,10 @@ pub async fn fetch_userinfo(
let content_type: Mime = userinfo_response let content_type: Mime = userinfo_response
.headers() .headers()
.get(CONTENT_TYPE) .typed_try_get::<ContentType>()
.map_err(|_| UserInfoError::InvalidResponseContentTypeValue)?
.ok_or(UserInfoError::MissingResponseContentType)? .ok_or(UserInfoError::MissingResponseContentType)?
.to_str()? .into();
.parse()?;
if content_type.essence_str() != expected_content_type { if content_type.essence_str() != expected_content_type {
return Err(UserInfoError::UnexpectedResponseContentType { return Err(UserInfoError::UnexpectedResponseContentType {