From 6d547b25ac8d111b05f3ccfd4f8e57737ccd47f2 Mon Sep 17 00:00:00 2001 From: Michael Rossberg Date: Mon, 8 Jan 2024 09:40:47 +0100 Subject: [PATCH] s3s-aws: proxy: improve readability --- codegen/src/aws_proxy.rs | 14 +- crates/s3s-aws/src/proxy/generated.rs | 1210 ++++--------------------- crates/s3s-aws/src/proxy/meta.rs | 31 +- crates/s3s/src/response.rs | 7 +- 4 files changed, 212 insertions(+), 1050 deletions(-) diff --git a/codegen/src/aws_proxy.rs b/codegen/src/aws_proxy.rs index b3fe1214..3ddf30b1 100644 --- a/codegen/src/aws_proxy.rs +++ b/codegen/src/aws_proxy.rs @@ -19,7 +19,6 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes) { "use s3s::S3;" "use s3s::{S3Request, S3Response};" "use s3s::S3Result;" - "use s3s::header::{X_AMZ_REQUEST_ID, X_AMZ_ID_2};" "" "use tracing::debug;" "" @@ -88,18 +87,9 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes) { glines![ "match result {" " Ok(output) => {" - " let request_id = super::meta::request_id(&output)?;" - " let ext_request_id = super::meta::extended_request_id(&output)?;" + " let headers = super::meta::build_headers(&output)?;" " let output = try_from_aws(output)?;" - " debug!(?output);" - " let mut res = S3Response::new(output);" - " if let Some(val) = request_id {" - " res.headers.insert(X_AMZ_REQUEST_ID, val);" - " }" - " if let Some(val) = ext_request_id {" - " res.headers.insert(X_AMZ_ID_2, val);" - " }" - " Ok(res)" + " Ok(S3Response::new_with_headers(output, headers))" " }," " Err(e) => Err(wrap_sdk_error!(e))," "}" diff --git a/crates/s3s-aws/src/proxy/generated.rs b/crates/s3s-aws/src/proxy/generated.rs index 52bcbe44..63841b01 100644 --- a/crates/s3s-aws/src/proxy/generated.rs +++ b/crates/s3s-aws/src/proxy/generated.rs @@ -4,7 +4,6 @@ use super::*; use crate::conv::{try_from_aws, try_into_aws}; -use s3s::header::{X_AMZ_ID_2, X_AMZ_REQUEST_ID}; use s3s::S3Result; use s3s::S3; use s3s::{S3Request, S3Response}; @@ -29,18 +28,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -70,18 +60,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -136,18 +117,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -174,18 +146,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -232,18 +195,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -262,18 +216,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -293,18 +238,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -323,18 +259,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -353,18 +280,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -383,18 +301,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -414,18 +323,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -444,18 +344,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -475,18 +366,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -505,18 +387,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -535,18 +408,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -565,18 +429,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -595,18 +450,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -625,18 +471,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -660,18 +497,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -692,18 +520,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -727,18 +546,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -757,18 +567,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -788,18 +589,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -818,18 +610,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -849,18 +632,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -879,18 +653,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -909,18 +674,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -939,18 +695,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -970,18 +717,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1000,18 +738,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1030,18 +759,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1060,18 +780,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1091,18 +802,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1121,18 +823,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1151,18 +844,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1181,18 +865,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1211,18 +886,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1241,18 +907,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1271,18 +928,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1301,18 +949,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1331,18 +970,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1361,18 +991,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1407,18 +1028,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1440,18 +1052,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1479,18 +1082,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1512,18 +1106,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1542,18 +1127,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1575,18 +1151,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1608,18 +1175,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1640,18 +1198,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1670,18 +1219,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1697,18 +1237,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1737,18 +1268,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1768,18 +1290,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1798,18 +1311,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1829,18 +1333,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1860,18 +1355,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1887,18 +1373,9 @@ impl S3 for Proxy { let result = self.0.list_buckets().send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1924,18 +1401,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1962,18 +1430,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -1999,18 +1458,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2038,18 +1488,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2073,18 +1514,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2105,18 +1537,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2144,18 +1567,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2176,18 +1590,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2209,18 +1614,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2242,18 +1638,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2273,18 +1660,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2305,18 +1683,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2337,18 +1706,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2370,18 +1730,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2402,18 +1753,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2434,18 +1776,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2466,18 +1799,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2500,18 +1824,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2534,18 +1849,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2567,18 +1873,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2600,18 +1897,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2634,18 +1922,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2667,18 +1946,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2729,18 +1999,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2771,18 +2032,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2807,18 +2059,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2842,18 +2085,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2879,18 +2113,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2915,18 +2140,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2948,18 +2164,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -2983,18 +2190,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -3023,18 +2221,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -3065,18 +2254,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -3112,18 +2292,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } @@ -3180,18 +2351,9 @@ impl S3 for Proxy { let result = b.send().await; match result { Ok(output) => { - let request_id = super::meta::request_id(&output)?; - let ext_request_id = super::meta::extended_request_id(&output)?; + let headers = super::meta::build_headers(&output)?; let output = try_from_aws(output)?; - debug!(?output); - let mut res = S3Response::new(output); - if let Some(val) = request_id { - res.headers.insert(X_AMZ_REQUEST_ID, val); - } - if let Some(val) = ext_request_id { - res.headers.insert(X_AMZ_ID_2, val); - } - Ok(res) + Ok(S3Response::new_with_headers(output, headers)) } Err(e) => Err(wrap_sdk_error!(e)), } diff --git a/crates/s3s-aws/src/proxy/meta.rs b/crates/s3s-aws/src/proxy/meta.rs index 87d1e4f4..fadd9ae6 100644 --- a/crates/s3s-aws/src/proxy/meta.rs +++ b/crates/s3s-aws/src/proxy/meta.rs @@ -1,16 +1,23 @@ -use s3s::{s3_error, S3Result}; +use s3s::{ + header::{X_AMZ_ID_2, X_AMZ_REQUEST_ID}, + s3_error, S3Result, +}; use aws_sdk_s3::operation::{RequestId, RequestIdExt}; -use hyper::header::HeaderValue; +use hyper::{header::HeaderValue, HeaderMap}; -pub fn request_id(x: &impl RequestId) -> S3Result> { - let Some(id) = x.request_id() else { return Ok(None) }; - let val = HeaderValue::from_str(id).map_err(|_| s3_error!(InternalError, "invalid request id"))?; - Ok(Some(val)) -} - -pub fn extended_request_id(x: &impl RequestIdExt) -> S3Result> { - let Some(id) = x.extended_request_id() else { return Ok(None) }; - let val = HeaderValue::from_str(id).map_err(|_| s3_error!(InternalError, "invalid extended request id"))?; - Ok(Some(val)) +pub fn build_headers(output: &T) -> S3Result> +where + T: RequestId + RequestIdExt, +{ + let mut header = HeaderMap::new(); + if let Some(id) = output.request_id() { + let val = HeaderValue::from_str(id).map_err(|_| s3_error!(InternalError, "invalid request id"))?; + header.insert(X_AMZ_REQUEST_ID, val); + } + if let Some(id) = output.extended_request_id() { + let val = HeaderValue::from_str(id).map_err(|_| s3_error!(InternalError, "invalid extended request id"))?; + header.insert(X_AMZ_ID_2, val); + } + Ok(header) } diff --git a/crates/s3s/src/response.rs b/crates/s3s/src/response.rs index 5074e406..ab1b1e00 100644 --- a/crates/s3s/src/response.rs +++ b/crates/s3s/src/response.rs @@ -17,13 +17,16 @@ pub struct S3Response { } impl S3Response { - pub fn new(output: T) -> Self { + pub fn new_with_headers(output: T, headers: HeaderMap) -> Self { Self { output, - headers: HeaderMap::new(), + headers, extensions: Extensions::new(), } } + pub fn new(output: T) -> Self { + Self::new_with_headers(output, HeaderMap::new()) + } pub fn map_output(self, f: impl FnOnce(T) -> U) -> S3Response { S3Response {