You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-11-20 12:02:22 +03:00
Remove the ServerLayer from mas-http
This commit is contained in:
@@ -20,5 +20,5 @@ pub mod json_request;
|
||||
pub mod json_response;
|
||||
pub mod otel;
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
pub(crate) mod client;
|
||||
pub(crate) mod server;
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
// Copyright 2022 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.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use http::{Request, Response};
|
||||
use opentelemetry::KeyValue;
|
||||
use tower::{util::BoxCloneService, Layer, Service, ServiceExt};
|
||||
use tower_http::compression::{CompressionBody, CompressionLayer};
|
||||
|
||||
use super::otel::TraceLayer;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ServerLayer<ReqBody> {
|
||||
listener_name: Option<String>,
|
||||
_t: PhantomData<ReqBody>,
|
||||
}
|
||||
|
||||
impl<B> Clone for ServerLayer<B> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
listener_name: self.listener_name.clone(),
|
||||
_t: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<B> ServerLayer<B> {
|
||||
#[must_use]
|
||||
pub fn new(listener_name: Option<String>) -> Self {
|
||||
Self {
|
||||
listener_name,
|
||||
_t: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<ReqBody, ResBody, S> Layer<S> for ServerLayer<ReqBody>
|
||||
where
|
||||
S: Service<Request<ReqBody>, Response = Response<ResBody>> + Clone + Send + 'static,
|
||||
S::Future: Send + 'static,
|
||||
S::Error: std::fmt::Display,
|
||||
ReqBody: http_body::Body + 'static,
|
||||
ResBody: http_body::Body + Send + 'static,
|
||||
{
|
||||
#[allow(clippy::type_complexity)]
|
||||
type Service = BoxCloneService<Request<ReqBody>, Response<CompressionBody<ResBody>>, S::Error>;
|
||||
|
||||
fn layer(&self, inner: S) -> Self::Service {
|
||||
let compression = CompressionLayer::new();
|
||||
|
||||
#[cfg(feature = "axum")]
|
||||
let mut trace = TraceLayer::axum();
|
||||
|
||||
#[cfg(not(feature = "axum"))]
|
||||
let mut trace = TraceLayer::http_server();
|
||||
|
||||
if let Some(name) = &self.listener_name {
|
||||
trace = trace.with_static_attribute(KeyValue::new("listener", name.clone()));
|
||||
}
|
||||
|
||||
(compression, trace).layer(inner).boxed_clone()
|
||||
}
|
||||
}
|
||||
@@ -31,9 +31,12 @@ mod layers;
|
||||
mod service;
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
pub use self::client::{
|
||||
make_traced_client, make_traced_connector, make_untraced_client, ClientInitError, TracedClient,
|
||||
TracedConnector, UntracedClient, UntracedConnector,
|
||||
pub use self::{
|
||||
client::{
|
||||
make_traced_client, make_traced_connector, make_untraced_client, ClientInitError,
|
||||
TracedClient, TracedConnector, UntracedClient, UntracedConnector,
|
||||
},
|
||||
layers::client::{ClientLayer, ClientService},
|
||||
};
|
||||
pub use self::{
|
||||
ext::{set_propagator, CorsLayerExt, ServiceExt as HttpServiceExt},
|
||||
@@ -41,12 +44,10 @@ pub use self::{
|
||||
body_to_bytes_response::{self, BodyToBytesResponse, BodyToBytesResponseLayer},
|
||||
bytes_to_body_request::{self, BytesToBodyRequest, BytesToBodyRequestLayer},
|
||||
catch_http_codes::{self, CatchHttpCodes, CatchHttpCodesLayer},
|
||||
client::{ClientLayer, ClientService},
|
||||
form_urlencoded_request::{self, FormUrlencodedRequest, FormUrlencodedRequestLayer},
|
||||
json_request::{self, JsonRequest, JsonRequestLayer},
|
||||
json_response::{self, JsonResponse, JsonResponseLayer},
|
||||
otel,
|
||||
server::ServerLayer,
|
||||
},
|
||||
service::{BoxCloneSyncService, HttpService},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user