1+ use crate :: cors:: { S3_PREFLIGHT_VARY , append_vary_headers} ;
12use aruna_core:: structs:: { BucketCorsConfiguration , BucketCorsRule } ;
2- use http:: header:: { HeaderName , HeaderValue , VARY } ;
3+ use http:: header:: { HeaderName , HeaderValue } ;
34use http:: { Method , StatusCode } ;
45use s3s:: HttpResponse ;
56use s3s:: dto:: { CORSConfiguration , CORSRule , GetBucketCorsOutput } ;
@@ -18,9 +19,6 @@ pub(crate) const MAX_AGE_HEADER: &str = "access-control-max-age";
1819const WILDCARD : & str = "*" ;
1920const VALID_CORS_METHODS : & [ & str ] = & [ "GET" , "PUT" , "HEAD" , "POST" , "DELETE" ] ;
2021
21- pub ( crate ) const PREFLIGHT_VARY : & [ & str ] =
22- & [ ORIGIN_HEADER , REQUEST_METHOD_HEADER , REQUEST_HEADERS_HEADER ] ;
23-
2422#[ derive( Debug , Clone , PartialEq , Eq ) ]
2523pub ( crate ) struct MatchedCorsRule {
2624 pub allow_origin : String ,
@@ -284,14 +282,14 @@ pub(crate) fn build_preflight_response(matched_rule: MatchedCorsRule) -> HttpRes
284282 & max_age_seconds. to_string ( ) ,
285283 ) ;
286284 }
287- append_vary_headers ( response. headers_mut ( ) , PREFLIGHT_VARY ) ;
285+ append_vary_headers ( response. headers_mut ( ) , S3_PREFLIGHT_VARY ) ;
288286 response
289287}
290288
291289pub ( crate ) fn build_preflight_forbidden_response ( ) -> HttpResponse {
292290 let mut response = HttpResponse :: new ( s3s:: Body :: empty ( ) ) ;
293291 * response. status_mut ( ) = StatusCode :: FORBIDDEN ;
294- append_vary_headers ( response. headers_mut ( ) , PREFLIGHT_VARY ) ;
292+ append_vary_headers ( response. headers_mut ( ) , S3_PREFLIGHT_VARY ) ;
295293 response
296294}
297295
@@ -329,39 +327,10 @@ fn append_header<T>(response: &mut http::Response<T>, name: HeaderName, value: &
329327 }
330328}
331329
332- fn append_vary_headers ( headers : & mut http:: HeaderMap , values : & [ & str ] ) {
333- let mut vary_values = headers
334- . get ( VARY )
335- . and_then ( |value| value. to_str ( ) . ok ( ) )
336- . map ( |value| {
337- value
338- . split ( ',' )
339- . map ( str:: trim)
340- . filter ( |entry| !entry. is_empty ( ) )
341- . map ( str:: to_owned)
342- . collect :: < Vec < _ > > ( )
343- } )
344- . unwrap_or_default ( ) ;
345-
346- for value in values {
347- if !vary_values
348- . iter ( )
349- . any ( |existing| existing. eq_ignore_ascii_case ( value) )
350- {
351- vary_values. push ( ( * value) . to_string ( ) ) ;
352- }
353- }
354-
355- if !vary_values. is_empty ( )
356- && let Ok ( value) = HeaderValue :: from_str ( & vary_values. join ( ", " ) )
357- {
358- headers. insert ( VARY , value) ;
359- }
360- }
361-
362330#[ cfg( test) ]
363331mod tests {
364332 use super :: * ;
333+ use http:: header:: VARY ;
365334
366335 #[ test]
367336 fn converts_cors_configuration_between_dto_and_core ( ) {
0 commit comments