fix: axum inbox

Co-Authored-By: j0 <me@j0.lol>
This commit is contained in:
藍+85CD 2024-07-25 17:29:26 +08:00
parent 8f0fdfaea9
commit 4d7ebc3493
No known key found for this signature in database
GPG key ID: BCB0111111111111

View file

@ -11,9 +11,9 @@ use crate::{
};
use axum::{
async_trait,
body::{Bytes, HttpBody},
body::{Body, HttpBody},
extract::FromRequest,
http::{Request, StatusCode},
http::StatusCode,
response::{IntoResponse, Response},
};
use http::{HeaderMap, Method, Uri};
@ -59,21 +59,23 @@ pub struct ActivityData {
}
#[async_trait]
impl<S, B> FromRequest<S, B> for ActivityData
impl<S> FromRequest<S> for ActivityData
where
Bytes: FromRequest<S, B>,
B: HttpBody + Send + 'static,
Body: HttpBody + Send + 'static,
S: Send + Sync,
<B as HttpBody>::Error: std::fmt::Display,
<B as HttpBody>::Data: Send,
<axum::body::Body as HttpBody>::Error: std::fmt::Display,
<axum::body::Body as HttpBody>::Data: Send,
{
type Rejection = Response;
async fn from_request(req: Request<B>, _state: &S) -> Result<Self, Self::Rejection> {
async fn from_request(
req: axum::extract::Request,
_state: &S,
) -> Result<Self, Self::Rejection> {
let (parts, body) = req.into_parts();
// this wont work if the body is an long running stream
let bytes = hyper::body::to_bytes(body)
let bytes = axum::body::to_bytes(body, usize::MAX)
.await
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()).into_response())?;