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

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.
This commit is contained in:
Quentin Gliech
2024-07-02 10:38:05 +02:00
parent f338aacf26
commit e7f50a92d6
13 changed files with 56 additions and 68 deletions

48
Cargo.lock generated
View File

@@ -2369,9 +2369,9 @@ dependencies = [
[[package]]
name = "http-range-header"
version = "0.3.1"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "add0ab9360ddbd88cfeb3bd9574a1d85cfdfa14db10b3e21d3700dbc4328758f"
checksum = "08a397c49fec283e3d6211adbe480be95aae5f304cfb923e9970e08956d5168a"
[[package]]
name = "httparse"
@@ -3155,12 +3155,15 @@ dependencies = [
"async-trait",
"axum",
"axum-extra",
"bytes",
"chrono",
"data-encoding",
"futures-util",
"headers",
"http 1.1.0",
"http-body 1.0.0",
"http-body-util",
"hyper-util",
"icu_locid",
"mas-data-model",
"mas-http",
@@ -3243,7 +3246,7 @@ dependencies = [
"sqlx",
"tokio",
"tower",
"tower-http 0.4.4",
"tower-http",
"tracing",
"tracing-appender",
"tracing-opentelemetry",
@@ -3367,7 +3370,7 @@ dependencies = [
"time",
"tokio",
"tower",
"tower-http 0.4.4",
"tower-http",
"tracing",
"tracing-subscriber",
"ulid",
@@ -3392,6 +3395,7 @@ dependencies = [
"mas-tower",
"opentelemetry",
"opentelemetry-semantic-conventions",
"pin-project-lite",
"rustls 0.23.10",
"rustls-platform-verifier",
"serde",
@@ -3400,7 +3404,7 @@ dependencies = [
"thiserror",
"tokio",
"tower",
"tower-http 0.5.2",
"tower-http",
"tracing",
"tracing-opentelemetry",
]
@@ -3547,7 +3551,7 @@ dependencies = [
"tokio-rustls",
"tokio-test",
"tower",
"tower-http 0.5.2",
"tower-http",
"tracing",
"tracing-subscriber",
]
@@ -6404,31 +6408,6 @@ dependencies = [
"tracing",
]
[[package]]
name = "tower-http"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61c5bb1d698276a2443e5ecfabc1008bf15a36c12e6a7176e7bf089ea9131140"
dependencies = [
"bitflags 2.6.0",
"bytes",
"futures-core",
"futures-util",
"http 0.2.12",
"http-body 0.4.6",
"http-range-header",
"httpdate",
"mime",
"mime_guess",
"percent-encoding",
"pin-project-lite",
"tokio",
"tokio-util",
"tower-layer",
"tower-service",
"tracing",
]
[[package]]
name = "tower-http"
version = "0.5.2"
@@ -6441,12 +6420,19 @@ dependencies = [
"http 1.1.0",
"http-body 1.0.0",
"http-body-util",
"http-range-header",
"httpdate",
"iri-string",
"mime",
"mime_guess",
"percent-encoding",
"pin-project-lite",
"tokio",
"tokio-util",
"tower",
"tower-layer",
"tower-service",
"tracing",
]
[[package]]

View File

@@ -209,6 +209,11 @@ features = ["full"]
version = "0.4.13"
features = ["util"]
# Tower HTTP layers
[workspace.dependencies.tower-http]
version = "0.5.2"
features = ["cors", "fs", "add-extension"]
# Logging and tracing
[workspace.dependencies.tracing]
version = "0.1.40"

View File

@@ -15,12 +15,15 @@ workspace = true
async-trait.workspace = true
axum.workspace = true
axum-extra.workspace = true
bytes = "1.6.0"
chrono.workspace = true
data-encoding = "2.6.0"
futures-util = "0.3.30"
headers.workspace = true
http.workspace = true
http-body.workspace = true
http-body-util.workspace = true
hyper-util.workspace = true
icu_locid = "1.4.0"
mime = "0.3.17"
rand.workspace = true

View File

@@ -16,14 +16,14 @@ use std::collections::HashMap;
use async_trait::async_trait;
use axum::{
body::HttpBody,
extract::{
rejection::{FailedToDeserializeForm, FormRejection, TypedHeaderRejectionReason},
Form, FromRequest, FromRequestParts, TypedHeader,
rejection::{FailedToDeserializeForm, FormRejection},
Form, FromRequest, FromRequestParts,
},
response::IntoResponse,
BoxError, Json,
};
use axum_extra::typed_header::{TypedHeader, TypedHeaderRejectionReason};
use headers::{authorization::Basic, Authorization};
use http::{Request, StatusCode};
use mas_data_model::{Client, JwksOrJwksUri};
@@ -337,18 +337,18 @@ impl IntoResponse for ClientAuthorizationError {
}
#[async_trait]
impl<S, B, F> FromRequest<S, B> for ClientAuthorization<F>
impl<S, F> FromRequest<S> for ClientAuthorization<F>
where
F: DeserializeOwned,
B: HttpBody + Send + 'static,
B::Data: Send,
B::Error: Into<BoxError>,
S: Send + Sync,
{
type Rejection = ClientAuthorizationError;
#[allow(clippy::too_many_lines)]
async fn from_request(req: Request<B>, state: &S) -> Result<Self, Self::Rejection> {
async fn from_request(
req: Request<axum::body::Body>,
state: &S,
) -> Result<Self, Self::Rejection> {
// Split the request into parts so we can extract some headers
let (mut parts, body) = req.into_parts();

View File

@@ -15,8 +15,9 @@
use axum::{
http::StatusCode,
response::{IntoResponse, Response},
Extension, TypedHeader,
Extension,
};
use axum_extra::typed_header::TypedHeader;
use headers::ContentType;
use mas_templates::ErrorContext;

View File

@@ -1,4 +1,4 @@
// Copyright 2022 The Matrix.org Foundation C.I.C.
// Copyright 2022-2024 The Matrix.org Foundation C.I.C.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -12,7 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use axum::body::Full;
use http_body_util::Full;
use hyper_util::rt::TokioExecutor;
use mas_http::{
make_traced_connector, BodyToBytesResponseLayer, Client, ClientLayer, ClientService,
HttpService, TracedClient, TracedConnector,
@@ -50,7 +51,7 @@ impl HttpClientFactory {
B: axum::body::HttpBody + Send,
B::Data: Send,
{
let client = Client::builder().build(self.traced_connector.clone());
let client = Client::builder(TokioExecutor::new()).build(self.traced_connector.clone());
self.client_layer
.clone()
.with_category(category)

View File

@@ -12,10 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use axum::{
response::{IntoResponse, Response},
TypedHeader,
};
use axum::response::{IntoResponse, Response};
use axum_extra::typed_header::TypedHeader;
use headers::ContentType;
use mas_jose::jwt::Jwt;
use mime::Mime;

View File

@@ -16,14 +16,13 @@ use std::{collections::HashMap, error::Error};
use async_trait::async_trait;
use axum::{
body::HttpBody,
extract::{
rejection::{FailedToDeserializeForm, FormRejection, TypedHeaderRejectionReason},
Form, FromRequest, FromRequestParts, TypedHeader,
rejection::{FailedToDeserializeForm, FormRejection},
Form, FromRequest, FromRequestParts,
},
response::{IntoResponse, Response},
BoxError,
};
use axum_extra::typed_header::{TypedHeader, TypedHeaderRejectionReason};
use headers::{authorization::Bearer, Authorization, Header, HeaderMapExt, HeaderName};
use http::{header::WWW_AUTHENTICATE, HeaderMap, HeaderValue, Request, StatusCode};
use mas_data_model::Session;
@@ -289,17 +288,17 @@ where
}
#[async_trait]
impl<S, B, F> FromRequest<S, B> for UserAuthorization<F>
impl<S, F> FromRequest<S> for UserAuthorization<F>
where
F: DeserializeOwned,
B: HttpBody + Send + 'static,
B::Data: Send,
B::Error: Into<BoxError>,
S: Send + Sync,
{
type Rejection = UserAuthorizationError;
async fn from_request(req: Request<B>, state: &S) -> Result<Self, Self::Rejection> {
async fn from_request(
req: Request<axum::body::Body>,
state: &S,
) -> Result<Self, Self::Rejection> {
let (mut parts, body) = req.into_parts();
let header =
TypedHeader::<Authorization<Bearer>>::from_request_parts(&mut parts, state).await;

View File

@@ -33,7 +33,7 @@ serde_yaml = "0.9.34"
sqlx.workspace = true
tokio.workspace = true
tower.workspace = true
tower-http = { version = "0.4.4", features = ["fs"] }
tower-http.workspace = true
url.workspace = true
zeroize = "1.8.1"

View File

@@ -30,7 +30,7 @@ sentry = { version = "0.31.8", default-features = false }
# Web server
hyper.workspace = true
tower.workspace = true
tower-http = { version = "0.4.4", features = ["cors"] }
tower-http.workspace = true
axum.workspace = true
axum-macros = "0.4.1"
axum-extra.workspace = true

View File

@@ -25,12 +25,13 @@ opentelemetry.workspace = true
opentelemetry-semantic-conventions.workspace = true
rustls = { workspace = true, optional = true }
rustls-platform-verifier = { workspace = true, optional = true }
pin-project-lite = "0.2.14"
serde.workspace = true
serde_json.workspace = true
serde_urlencoded = "0.7.1"
thiserror.workspace = true
tower.workspace = true
tower-http = { version = "0.5.2", features = ["cors"] }
tower-http.workspace = true
tracing.workspace = true
tracing-opentelemetry.workspace = true

View File

@@ -1,4 +1,4 @@
// Copyright 2022 The Matrix.org Foundation C.I.C.
// Copyright 2022-2024 The Matrix.org Foundation C.I.C.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::time::Duration;
use headers::{ContentLength, HeaderMapExt, Host, UserAgent};
use http::{header::USER_AGENT, HeaderValue, Request, Response};
use hyper_util::client::legacy::connect::HttpInfo;
@@ -35,7 +33,6 @@ use tower::{
use tower_http::{
follow_redirect::{FollowRedirect, FollowRedirectLayer},
set_header::{SetRequestHeader, SetRequestHeaderLayer},
timeout::{Timeout, TimeoutLayer},
};
use tracing::Span;
@@ -45,7 +42,7 @@ pub type ClientService<S> = SetRequestHeader<
ConcurrencyLimit<
FollowRedirect<
TraceService<
TraceContextService<Timeout<S>>,
TraceContextService<S>,
MakeSpanForRequest,
EnrichSpanOnResponse,
EnrichSpanOnError,
@@ -183,7 +180,6 @@ pub struct ClientLayer {
follow_redirect_layer: FollowRedirectLayer,
trace_layer: TraceLayer<MakeSpanForRequest, EnrichSpanOnResponse, EnrichSpanOnError>,
trace_context_layer: TraceContextLayer,
timeout_layer: TimeoutLayer,
duration_recorder_layer: DurationRecorderLayer<OnRequestLabels, OnResponseLabels, KeyValue>,
in_flight_counter_layer: InFlightCounterLayer<OnRequestLabels>,
}
@@ -208,7 +204,6 @@ impl ClientLayer {
.on_response(EnrichSpanOnResponse)
.on_error(EnrichSpanOnError),
trace_context_layer: TraceContextLayer::new(),
timeout_layer: TimeoutLayer::new(Duration::from_secs(10)),
duration_recorder_layer: DurationRecorderLayer::new("http.client.duration")
.on_request(OnRequestLabels::default())
.on_response(OnResponseLabels)
@@ -253,7 +248,6 @@ where
&self.follow_redirect_layer,
&self.trace_layer,
&self.trace_context_layer,
&self.timeout_layer,
)
.layer(inner)
}

View File

@@ -25,7 +25,7 @@ thiserror.workspace = true
tokio.workspace = true
tokio-rustls = "0.26.0"
tower.workspace = true
tower-http = { version = "0.5.2", features = ["add-extension"] }
tower-http.workspace = true
tracing.workspace = true
[dev-dependencies]