Unverified Commit 7b8be3c9 authored by Nugine's avatar Nugine
Browse files

s3s: http: take_bytes

parent 5cc2168a
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -213,6 +213,14 @@ impl Body {
        }
    }

    pub fn take_bytes(&mut self) -> Option<Bytes> {
        match mem::take(&mut self.kind) {
            Kind::Empty => Some(Bytes::new()),
            Kind::Once { inner } => Some(inner),
            _ => None,
        }
    }

    fn into_hyper(self) -> hyper::Body {
        match self.kind {
            Kind::Empty => hyper::Body::empty(),
+3 −3
Original line number Diff line number Diff line
@@ -164,7 +164,7 @@ pub fn take_xml_body<T>(req: &mut Request) -> S3Result<T>
where
    T: for<'xml> xml::Deserialize<'xml>,
{
    let bytes = req.body.bytes().expect("full body not found");
    let bytes = req.body.take_bytes().expect("full body not found");
    if bytes.is_empty() {
        return Err(S3ErrorCode::MissingRequestBodyError.into());
    }
@@ -179,7 +179,7 @@ pub fn take_opt_xml_body<T>(req: &mut Request) -> S3Result<Option<T>>
where
    T: for<'xml> xml::Deserialize<'xml>,
{
    let bytes = req.body.bytes().expect("full body not found");
    let bytes = req.body.take_bytes().expect("full body not found");
    if bytes.is_empty() {
        return Ok(None);
    }
@@ -191,7 +191,7 @@ where
}

pub fn take_string_body(req: &mut Request) -> S3Result<String> {
    let bytes = req.body.bytes().expect("full body not found");
    let bytes = req.body.take_bytes().expect("full body not found");
    match String::from_utf8_simd(bytes.into()) {
        Some(s) => Ok(s),
        None => Err(invalid_request!("expected UTF-8 body")),