From ea7fb901ebc316bba53d248a2f8bd7a3455f5791 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 7 Jan 2022 16:23:04 +0100 Subject: Implement {Put,Get,Delete}BucketCors and CORS in general - OPTIONS request against API endpoint - Returning corresponding CORS headers on API calls - Returning corresponding CORS headers on website GET's --- src/api/s3_router.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/api/s3_router.rs') diff --git a/src/api/s3_router.rs b/src/api/s3_router.rs index 9add5e4a..51020a81 100644 --- a/src/api/s3_router.rs +++ b/src/api/s3_router.rs @@ -327,6 +327,7 @@ pub enum Endpoint { part_number_marker: Option, upload_id: String, }, + Options, PutBucketAccelerateConfiguration { }, PutBucketAcl { @@ -434,6 +435,10 @@ impl Endpoint { .unwrap_or((path.to_owned(), "")) }; + if *req.method() == Method::OPTIONS { + return Ok((Self::Options, Some(bucket))); + } + let key = percent_encoding::percent_decode_str(key) .decode_utf8()? .into_owned(); @@ -665,7 +670,6 @@ impl Endpoint { GetBucketAccelerateConfiguration, GetBucketAcl, GetBucketAnalyticsConfiguration, - GetBucketCors, GetBucketEncryption, GetBucketIntelligentTieringConfiguration, GetBucketInventoryConfiguration, @@ -711,6 +715,9 @@ impl Endpoint { GetBucketWebsite, PutBucketWebsite, DeleteBucketWebsite, + GetBucketCors, + PutBucketCors, + DeleteBucketCors, ] }; if readonly { @@ -1027,7 +1034,7 @@ mod tests { OWNER_DELETE "/" => DeleteBucket DELETE "/?analytics&id=list1" => DeleteBucketAnalyticsConfiguration DELETE "/?analytics&id=Id" => DeleteBucketAnalyticsConfiguration - DELETE "/?cors" => DeleteBucketCors + OWNER_DELETE "/?cors" => DeleteBucketCors DELETE "/?encryption" => DeleteBucketEncryption DELETE "/?intelligent-tiering&id=Id" => DeleteBucketIntelligentTieringConfiguration DELETE "/?inventory&id=list1" => DeleteBucketInventoryConfiguration @@ -1050,7 +1057,7 @@ mod tests { GET "/?accelerate" => GetBucketAccelerateConfiguration GET "/?acl" => GetBucketAcl GET "/?analytics&id=Id" => GetBucketAnalyticsConfiguration - GET "/?cors" => GetBucketCors + OWNER_GET "/?cors" => GetBucketCors GET "/?encryption" => GetBucketEncryption GET "/?intelligent-tiering&id=Id" => GetBucketIntelligentTieringConfiguration GET "/?inventory&id=list1" => GetBucketInventoryConfiguration @@ -1126,7 +1133,7 @@ mod tests { PUT "/?acl" => PutBucketAcl PUT "/?analytics&id=report1" => PutBucketAnalyticsConfiguration PUT "/?analytics&id=Id" => PutBucketAnalyticsConfiguration - PUT "/?cors" => PutBucketCors + OWNER_PUT "/?cors" => PutBucketCors PUT "/?encryption" => PutBucketEncryption PUT "/?intelligent-tiering&id=Id" => PutBucketIntelligentTieringConfiguration PUT "/?inventory&id=report1" => PutBucketInventoryConfiguration -- cgit v1.2.3