aboutsummaryrefslogtreecommitdiff
path: root/src/api/signature/streaming.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2024-02-05 18:49:54 +0100
committerAlex Auvolat <alex@adnab.me>2024-02-05 18:49:54 +0100
commit0bb5b77530ad432e4c77f13b395fe74613812337 (patch)
tree9734470cff2ba2ce848abc0fdb9b0032c37420b8 /src/api/signature/streaming.rs
parent6e69a1fffc715c752a399750c1e26aa46683dbb2 (diff)
downloadgarage-0bb5b77530ad432e4c77f13b395fe74613812337.tar.gz
garage-0bb5b77530ad432e4c77f13b395fe74613812337.zip
[dep-upgrade-202402] wip: port to http/hyper crates v1
Diffstat (limited to 'src/api/signature/streaming.rs')
-rw-r--r--src/api/signature/streaming.rs32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/api/signature/streaming.rs b/src/api/signature/streaming.rs
index c8358c4f..8fb0c4ef 100644
--- a/src/api/signature/streaming.rs
+++ b/src/api/signature/streaming.rs
@@ -5,22 +5,26 @@ use futures::prelude::*;
use futures::task;
use garage_model::key_table::Key;
use hmac::Mac;
-use hyper::body::Bytes;
-use hyper::{Body, Request};
+use http_body_util::{BodyStream, StreamBody};
+use hyper::body::{Bytes, Incoming as IncomingBody};
+use hyper::Request;
use garage_util::data::Hash;
use super::{compute_scope, sha256sum, HmacSha256, LONG_DATETIME};
+use crate::helpers::*;
use crate::signature::error::*;
+pub type ReqBody = BoxBody<Error>;
+
pub fn parse_streaming_body(
api_key: &Key,
- req: Request<Body>,
+ req: Request<IncomingBody>,
content_sha256: &mut Option<Hash>,
region: &str,
service: &str,
-) -> Result<Request<Body>, Error> {
+) -> Result<Request<ReqBody>, Error> {
match req.headers().get("x-amz-content-sha256") {
Some(header) if header == "STREAMING-AWS4-HMAC-SHA256-PAYLOAD" => {
let signature = content_sha256
@@ -47,19 +51,17 @@ pub fn parse_streaming_body(
.ok_or_internal_error("Unable to build signing HMAC")?;
Ok(req.map(move |body| {
- Body::wrap_stream(
- SignedPayloadStream::new(
- body.map_err(Error::from),
- signing_hmac,
- date,
- &scope,
- signature,
- )
- .map_err(Error::from),
- )
+ let body_stream = BodyStream::new(body)
+ .map(|x| x.map(|f| f.into_data().unwrap())) //TODO remove unwrap
+ .map_err(Error::from);
+ let signed_payload_stream =
+ SignedPayloadStream::new(body_stream, signing_hmac, date, &scope, signature)
+ .map(|x| x.map(hyper::body::Frame::data))
+ .map_err(Error::from);
+ ReqBody::new(StreamBody::new(signed_payload_stream))
}))
}
- _ => Ok(req),
+ _ => Ok(req.map(|body| ReqBody::new(http_body_util::BodyExt::map_err(body, Error::from)))),
}
}