Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit e7f50a9

Browse files
committed
Move tower-http dep to the workspace and adapt mas-axum-utils
We removed here the Timeout layer on the HTTP client service, because it required the body to be Default, which isn't the case anymore. Not sure what to do about it.
1 parent f338aac commit e7f50a9

File tree

13 files changed

+56
-68
lines changed

13 files changed

+56
-68
lines changed

Cargo.lock

Lines changed: 17 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ features = ["full"]
209209
version = "0.4.13"
210210
features = ["util"]
211211

212+
# Tower HTTP layers
213+
[workspace.dependencies.tower-http]
214+
version = "0.5.2"
215+
features = ["cors", "fs", "add-extension"]
216+
212217
# Logging and tracing
213218
[workspace.dependencies.tracing]
214219
version = "0.1.40"

crates/axum-utils/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ workspace = true
1515
async-trait.workspace = true
1616
axum.workspace = true
1717
axum-extra.workspace = true
18+
bytes = "1.6.0"
1819
chrono.workspace = true
1920
data-encoding = "2.6.0"
2021
futures-util = "0.3.30"
2122
headers.workspace = true
2223
http.workspace = true
2324
http-body.workspace = true
25+
http-body-util.workspace = true
26+
hyper-util.workspace = true
2427
icu_locid = "1.4.0"
2528
mime = "0.3.17"
2629
rand.workspace = true

crates/axum-utils/src/client_authorization.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ use std::collections::HashMap;
1616

1717
use async_trait::async_trait;
1818
use axum::{
19-
body::HttpBody,
2019
extract::{
21-
rejection::{FailedToDeserializeForm, FormRejection, TypedHeaderRejectionReason},
22-
Form, FromRequest, FromRequestParts, TypedHeader,
20+
rejection::{FailedToDeserializeForm, FormRejection},
21+
Form, FromRequest, FromRequestParts,
2322
},
2423
response::IntoResponse,
2524
BoxError, Json,
2625
};
26+
use axum_extra::typed_header::{TypedHeader, TypedHeaderRejectionReason};
2727
use headers::{authorization::Basic, Authorization};
2828
use http::{Request, StatusCode};
2929
use mas_data_model::{Client, JwksOrJwksUri};
@@ -337,18 +337,18 @@ impl IntoResponse for ClientAuthorizationError {
337337
}
338338

339339
#[async_trait]
340-
impl<S, B, F> FromRequest<S, B> for ClientAuthorization<F>
340+
impl<S, F> FromRequest<S> for ClientAuthorization<F>
341341
where
342342
F: DeserializeOwned,
343-
B: HttpBody + Send + 'static,
344-
B::Data: Send,
345-
B::Error: Into<BoxError>,
346343
S: Send + Sync,
347344
{
348345
type Rejection = ClientAuthorizationError;
349346

350347
#[allow(clippy::too_many_lines)]
351-
async fn from_request(req: Request<B>, state: &S) -> Result<Self, Self::Rejection> {
348+
async fn from_request(
349+
req: Request<axum::body::Body>,
350+
state: &S,
351+
) -> Result<Self, Self::Rejection> {
352352
// Split the request into parts so we can extract some headers
353353
let (mut parts, body) = req.into_parts();
354354

crates/axum-utils/src/fancy_error.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
use axum::{
1616
http::StatusCode,
1717
response::{IntoResponse, Response},
18-
Extension, TypedHeader,
18+
Extension,
1919
};
20+
use axum_extra::typed_header::TypedHeader;
2021
use headers::ContentType;
2122
use mas_templates::ErrorContext;
2223

crates/axum-utils/src/http_client_factory.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 The Matrix.org Foundation C.I.C.
1+
// Copyright 2022-2024 The Matrix.org Foundation C.I.C.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -12,7 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use axum::body::Full;
15+
use http_body_util::Full;
16+
use hyper_util::rt::TokioExecutor;
1617
use mas_http::{
1718
make_traced_connector, BodyToBytesResponseLayer, Client, ClientLayer, ClientService,
1819
HttpService, TracedClient, TracedConnector,
@@ -50,7 +51,7 @@ impl HttpClientFactory {
5051
B: axum::body::HttpBody + Send,
5152
B::Data: Send,
5253
{
53-
let client = Client::builder().build(self.traced_connector.clone());
54+
let client = Client::builder(TokioExecutor::new()).build(self.traced_connector.clone());
5455
self.client_layer
5556
.clone()
5657
.with_category(category)

crates/axum-utils/src/jwt.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use axum::{
16-
response::{IntoResponse, Response},
17-
TypedHeader,
18-
};
15+
use axum::response::{IntoResponse, Response};
16+
use axum_extra::typed_header::TypedHeader;
1917
use headers::ContentType;
2018
use mas_jose::jwt::Jwt;
2119
use mime::Mime;

crates/axum-utils/src/user_authorization.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ use std::{collections::HashMap, error::Error};
1616

1717
use async_trait::async_trait;
1818
use axum::{
19-
body::HttpBody,
2019
extract::{
21-
rejection::{FailedToDeserializeForm, FormRejection, TypedHeaderRejectionReason},
22-
Form, FromRequest, FromRequestParts, TypedHeader,
20+
rejection::{FailedToDeserializeForm, FormRejection},
21+
Form, FromRequest, FromRequestParts,
2322
},
2423
response::{IntoResponse, Response},
25-
BoxError,
2624
};
25+
use axum_extra::typed_header::{TypedHeader, TypedHeaderRejectionReason};
2726
use headers::{authorization::Bearer, Authorization, Header, HeaderMapExt, HeaderName};
2827
use http::{header::WWW_AUTHENTICATE, HeaderMap, HeaderValue, Request, StatusCode};
2928
use mas_data_model::Session;
@@ -289,17 +288,17 @@ where
289288
}
290289

291290
#[async_trait]
292-
impl<S, B, F> FromRequest<S, B> for UserAuthorization<F>
291+
impl<S, F> FromRequest<S> for UserAuthorization<F>
293292
where
294293
F: DeserializeOwned,
295-
B: HttpBody + Send + 'static,
296-
B::Data: Send,
297-
B::Error: Into<BoxError>,
298294
S: Send + Sync,
299295
{
300296
type Rejection = UserAuthorizationError;
301297

302-
async fn from_request(req: Request<B>, state: &S) -> Result<Self, Self::Rejection> {
298+
async fn from_request(
299+
req: Request<axum::body::Body>,
300+
state: &S,
301+
) -> Result<Self, Self::Rejection> {
303302
let (mut parts, body) = req.into_parts();
304303
let header =
305304
TypedHeader::<Authorization<Bearer>>::from_request_parts(&mut parts, state).await;

crates/cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ serde_yaml = "0.9.34"
3333
sqlx.workspace = true
3434
tokio.workspace = true
3535
tower.workspace = true
36-
tower-http = { version = "0.4.4", features = ["fs"] }
36+
tower-http.workspace = true
3737
url.workspace = true
3838
zeroize = "1.8.1"
3939

crates/handlers/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ sentry = { version = "0.31.8", default-features = false }
3030
# Web server
3131
hyper.workspace = true
3232
tower.workspace = true
33-
tower-http = { version = "0.4.4", features = ["cors"] }
33+
tower-http.workspace = true
3434
axum.workspace = true
3535
axum-macros = "0.4.1"
3636
axum-extra.workspace = true

0 commit comments

Comments
 (0)