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

Make HTTP request layers convert to Bytes

Add layer to convert a request's Bytes to a Body.
This commit is contained in:
Kévin Commaille
2022-08-19 18:01:16 +02:00
committed by Quentin Gliech
parent 669a1867b7
commit 348044afdc
8 changed files with 102 additions and 22 deletions

View File

@@ -21,7 +21,6 @@ use futures_util::{
};
use headers::{ContentType, HeaderMapExt};
use http::Request;
use http_body::Full;
use serde::Serialize;
use thiserror::Error;
use tower::{Layer, Service};
@@ -65,7 +64,7 @@ impl<S, T> JsonRequest<S, T> {
impl<S, T> Service<Request<T>> for JsonRequest<S, T>
where
S: Service<Request<Full<Bytes>>>,
S: Service<Request<Bytes>>,
S::Future: Send + 'static,
S::Error: 'static,
T: Serialize,
@@ -87,7 +86,7 @@ where
parts.headers.typed_insert(ContentType::json());
let body = match serde_json::to_vec(&body) {
Ok(body) => Full::new(Bytes::from(body)),
Ok(body) => Bytes::from(body),
Err(err) => return std::future::ready(Err(Error::serialize(err))).left_future(),
};