@@ -11,6 +11,7 @@ use http::header::ACCESS_CONTROL_ALLOW_HEADERS;
1111use http:: header:: ACCESS_CONTROL_ALLOW_METHODS ;
1212use http:: header:: ACCESS_CONTROL_ALLOW_ORIGIN ;
1313use http:: header:: ORIGIN ;
14+ use http:: header:: VARY ;
1415use http:: HeaderValue ;
1516use http:: Method ;
1617use http:: StatusCode ;
@@ -32,6 +33,7 @@ use std::sync::Arc;
3233use tokio:: net:: TcpListener ;
3334use tracing:: error;
3435use tracing:: info;
36+ use tracing:: trace;
3537
3638pub struct S3Server {
3739 s3service : S3Service ,
@@ -246,8 +248,7 @@ impl WrappingService {
246248 . map_err ( |e| {
247249 error ! ( "{e}" ) ;
248250 s3_error ! ( InvalidURI , "Invalid URI encoding" )
249- } ) ?;
250- let url_without_host = url
251+ } ) ?
251252 . split (
252253 & CONFIG
253254 . frontend
@@ -257,12 +258,21 @@ impl WrappingService {
257258 )
258259 . next ( )
259260 . ok_or_else ( || s3_error ! ( InternalError , "Invalid host url set" ) ) ?;
260- let bucket = match url_without_host. split ( "." ) . next ( ) {
261+
262+ let bucket = match url. split ( "." ) . next ( ) {
263+ Some ( empty) if empty. is_empty ( ) => {
264+ let mut iter = req. uri ( ) . path ( ) . split ( "/" ) ;
265+ trace ! ( ?iter) ;
266+ iter. next ( ) ; // first one is empty
267+ iter. next ( ) // next one is bucket
268+ . ok_or_else ( || s3_error ! ( InvalidURI , "No bucket set" ) ) ?
269+ }
261270 Some ( sub_bucket) => sub_bucket,
262271 None => {
263- url_without_host
264- . split ( "/" )
265- . next ( )
272+ let mut iter = req. uri ( ) . path ( ) . split ( "/" ) ;
273+ trace ! ( ?iter) ;
274+ iter. next ( ) ; // first one is empty
275+ iter. next ( ) // next one is bucket
266276 . ok_or_else ( || s3_error ! ( InvalidURI , "No bucket set" ) ) ?
267277 }
268278 } ;
@@ -304,6 +314,9 @@ impl WrappingService {
304314 } )
305315 . ok_or_else ( || s3_error ! ( NoSuchBucketPolicy , "No cors policy found for bucket" ) ) ?;
306316 let mut builder = hyper:: Response :: builder ( ) ;
317+ if !rule. allowed_origins . contains ( & "*" . to_string ( ) ) {
318+ builder = builder. header ( VARY , HeaderValue :: from_static ( "Origin" ) ) ;
319+ }
307320 for origin in rule. allowed_origins . iter ( ) {
308321 builder = builder. header (
309322 ACCESS_CONTROL_ALLOW_ORIGIN ,
0 commit comments