1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-08-09 04:22:45 +03:00

Upgrade axum to 0.5

This commit is contained in:
Quentin Gliech
2022-04-06 16:32:28 +02:00
parent 4e31fc6c84
commit 31bc8504c9
17 changed files with 65 additions and 79 deletions

View File

@@ -7,7 +7,7 @@ license = "Apache-2.0"
[dependencies]
async-trait = "0.1.52"
axum = { version = "0.4.8", features = ["headers"] }
axum = { version = "0.5.1", features = ["headers"] }
bincode = "1.3.3"
chrono = "0.4.19"
cookie = { version = "0.16.0", features = ["signed", "private", "percent-encode"] }

View File

@@ -223,9 +223,7 @@ where
// If it's missing it is fine
TypedHeaderRejectionReason::Missing => None,
// If the header could not be parsed, return the error
TypedHeaderRejectionReason::Error(_) => {
return Err(ClientAuthorizationError::InvalidHeader)
}
_ => return Err(ClientAuthorizationError::InvalidHeader),
},
};

View File

@@ -14,10 +14,13 @@
//! Private (encrypted) cookie jar, based on axum-extra's cookie jar
use std::marker::PhantomData;
use std::{convert::Infallible, marker::PhantomData};
use async_trait::async_trait;
use axum::extract::{Extension, FromRequest, RequestParts};
use axum::{
extract::{Extension, FromRequest, RequestParts},
response::IntoResponseParts,
};
pub use cookie::Cookie;
use data_encoding::BASE64URL_NOPAD;
use headers::HeaderMap;
@@ -68,12 +71,6 @@ impl<K> PrivateCookieJar<K> {
}
}
}
pub fn headers(self) -> HeaderMap {
let mut headers = HeaderMap::new();
self.set_cookies(&mut headers);
headers
}
}
#[async_trait]
@@ -91,13 +88,8 @@ where
let mut jar = cookie::CookieJar::new();
let mut private_jar = jar.private_mut(&key);
// TODO: remove this when axum 0.5 gets released
// https://github.com/tokio-rs/axum/pull/698
let empty_headers = HeaderMap::new();
let cookies = req
.headers()
.unwrap_or(&empty_headers)
.get_all(COOKIE)
.into_iter()
.filter_map(|value| value.to_str().ok())
@@ -118,6 +110,17 @@ where
}
}
impl<K> IntoResponseParts for PrivateCookieJar<K> {
type Error = Infallible;
fn into_response_parts(
self,
mut res: axum::response::ResponseParts,
) -> Result<axum::response::ResponseParts, Self::Error> {
self.set_cookies(res.headers_mut());
Ok(res)
}
}
#[derive(Debug, Error)]
#[error("could not decode cookie")]
pub enum CookieDecodeError {

View File

@@ -287,9 +287,7 @@ where
// If it's missing it is fine
TypedHeaderRejectionReason::Missing => None,
// If the header could not be parsed, return the error
TypedHeaderRejectionReason::Error(_) => {
return Err(UserAuthorizationError::InvalidHeader)
}
_ => return Err(UserAuthorizationError::InvalidHeader),
},
};