aboutsummaryrefslogtreecommitdiff
path: root/src/api/s3/post_object.rs
diff options
context:
space:
mode:
authorAlex <alex@adnab.me>2024-03-04 14:51:05 +0000
committerAlex <alex@adnab.me>2024-03-04 14:51:05 +0000
commit3168bb34a0082480660e945f7390a5ecab26c665 (patch)
tree2b9d53b65c41f074b772c2123f0a27893e33859a /src/api/s3/post_object.rs
parent512933a036be97ab01b8b2627b727d599b962715 (diff)
parentfb55682c66092921f766f82c16eb9e046f1bbb41 (diff)
downloadgarage-3168bb34a0082480660e945f7390a5ecab26c665.tar.gz
garage-3168bb34a0082480660e945f7390a5ecab26c665.zip
Merge pull request 'add request context helper' (#751) from yuka/garage:req-ctx into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/751
Diffstat (limited to 'src/api/s3/post_object.rs')
-rw-r--r--src/api/s3/post_object.rs28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/api/s3/post_object.rs b/src/api/s3/post_object.rs
index b542cc1a..66f8174c 100644
--- a/src/api/s3/post_object.rs
+++ b/src/api/s3/post_object.rs
@@ -120,6 +120,12 @@ pub async fn handle_post_object(
.bucket_helper()
.get_existing_bucket(bucket_id)
.await?;
+ let bucket_params = bucket.state.into_option().unwrap();
+ let matching_cors_rule = find_matching_cors_rule(
+ &bucket_params,
+ &Request::from_parts(head.clone(), empty_body::<Infallible>()),
+ )?
+ .cloned();
let decoded_policy = BASE64_STANDARD
.decode(policy)
@@ -213,11 +219,19 @@ pub async fn handle_post_object(
let headers = get_headers(&params)?;
let stream = field.map(|r| r.map_err(Into::into));
- let (_, md5) = save_stream(
+
+ let ctx = ReqCtx {
garage,
+ bucket_id,
+ bucket_name,
+ bucket_params,
+ api_key,
+ };
+
+ let (_, md5) = save_stream(
+ &ctx,
headers,
StreamLimiter::new(stream, conditions.content_length),
- &bucket,
&key,
None,
None,
@@ -234,7 +248,7 @@ pub async fn handle_post_object(
{
target
.query_pairs_mut()
- .append_pair("bucket", &bucket_name)
+ .append_pair("bucket", &ctx.bucket_name)
.append_pair("key", &key)
.append_pair("etag", &etag);
let target = target.to_string();
@@ -278,7 +292,7 @@ pub async fn handle_post_object(
let xml = s3_xml::PostObject {
xmlns: (),
location: s3_xml::Value(location),
- bucket: s3_xml::Value(bucket_name),
+ bucket: s3_xml::Value(ctx.bucket_name),
key: s3_xml::Value(key),
etag: s3_xml::Value(etag),
};
@@ -291,12 +305,8 @@ pub async fn handle_post_object(
}
};
- let matching_cors_rule = find_matching_cors_rule(
- &bucket,
- &Request::from_parts(head, empty_body::<Infallible>()),
- )?;
if let Some(rule) = matching_cors_rule {
- add_cors_headers(&mut resp, rule)
+ add_cors_headers(&mut resp, &rule)
.ok_or_internal_error("Invalid bucket CORS configuration")?;
}