Unverified Commit 70893f2e authored by Nugine's avatar Nugine
Browse files

s3s: service: full_body_limit

parent 1b0d935c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ use hyper::Body;

pub struct LengthLimit(pub u64);

pub const DEFAULT_LENGTH_LIMIT: u64 = 64 * 1024;
pub const DEFAULT_LENGTH_LIMIT: u64 = 2 * 1024 * 1024;

pub struct FullBody(pub Bytes);

+15 −1
Original line number Diff line number Diff line
@@ -15,17 +15,26 @@ use tracing::debug;
pub struct S3Service {
    s3: Box<dyn S3>,
    auth: Option<Box<dyn S3Auth>>,
    full_body_limit: u64,
}

impl S3Service {
    pub fn new(s3: Box<dyn S3>) -> Self {
        Self { s3, auth: None }
        Self {
            s3,
            auth: None,
            full_body_limit: crate::http::DEFAULT_LENGTH_LIMIT,
        }
    }

    pub fn set_auth(&mut self, auth: Box<dyn S3Auth>) {
        self.auth = Some(auth);
    }

    pub fn set_full_body_limit(&mut self, length_limit: u64) {
        self.full_body_limit = length_limit;
    }

    #[tracing::instrument(
        level = "debug",
        skip(self, req),
@@ -33,6 +42,11 @@ impl S3Service {
    )]
    pub async fn call(&self, mut req: http::Request) -> S3Result<http::Response> {
        debug!(?req);

        if self.full_body_limit > 0 {
            req.extensions_mut().insert(crate::http::LengthLimit(self.full_body_limit));
        }

        let result = crate::ops::call(&*self.s3, self.auth.as_deref(), &mut req).await;

        match result {