use max_request_size in axum.rs
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
999cc7ccf5
commit
19255c0c14
1 changed files with 11 additions and 5 deletions
|
@ -41,8 +41,6 @@ struct QueryParams {
|
||||||
user_id: Option<String>,
|
user_id: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
const MAX_BODY_SIZE: usize = 1024 * 1024 * 128; //TODO: conf?
|
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<T, S> FromRequest<S, axum::body::Body> for Ruma<T>
|
impl<T, S> FromRequest<S, axum::body::Body> for Ruma<T>
|
||||||
where
|
where
|
||||||
|
@ -54,9 +52,17 @@ where
|
||||||
async fn from_request(req: Request<axum::body::Body>, _state: &S) -> Result<Self, Self::Rejection> {
|
async fn from_request(req: Request<axum::body::Body>, _state: &S) -> Result<Self, Self::Rejection> {
|
||||||
let limited = req.with_limited_body();
|
let limited = req.with_limited_body();
|
||||||
let (mut parts, body) = limited.into_parts();
|
let (mut parts, body) = limited.into_parts();
|
||||||
let mut body = axum::body::to_bytes(body, MAX_BODY_SIZE)
|
let mut body = axum::body::to_bytes(
|
||||||
.await
|
body,
|
||||||
.map_err(|_| Error::BadRequest(ErrorKind::MissingToken, "Missing token."))?;
|
services()
|
||||||
|
.globals
|
||||||
|
.config
|
||||||
|
.max_request_size
|
||||||
|
.try_into()
|
||||||
|
.expect("failed to convert max request size"),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map_err(|_| Error::BadRequest(ErrorKind::MissingToken, "Missing token."))?;
|
||||||
|
|
||||||
let metadata = T::METADATA;
|
let metadata = T::METADATA;
|
||||||
let auth_header: Option<TypedHeader<Authorization<Bearer>>> = parts.extract().await?;
|
let auth_header: Option<TypedHeader<Authorization<Bearer>>> = parts.extract().await?;
|
||||||
|
|
Loading…
Add table
Reference in a new issue