File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,12 @@ defmodule ExAws.Operation.S3 do
6262 raise "#{ __MODULE__ } .perform/2 cannot perform operation on `nil` bucket"
6363 end
6464
65+ def add_bucket_to_path ( operation , % { virtual_host: true , bucket_as_host: true } = config ) do
66+ # When bucket_as_host is true, use the bucket name as the full hostname
67+ { put_in ( operation . path , ensure_absolute ( operation . path ) ) ,
68+ Map . put ( config , :host , operation . bucket ) }
69+ end
70+
6571 def add_bucket_to_path ( operation , % { virtual_host: true , host: base_host } = config ) do
6672 vhost_domain = "#{ operation . bucket } .#{ base_host } "
6773
Original file line number Diff line number Diff line change @@ -80,4 +80,24 @@ defmodule ExAws.Operation.S3Test do
8080 { processed_operation , _processed_config } = S3 . add_bucket_to_path ( operation , config )
8181 assert processed_operation . path == "/folder/"
8282 end
83+
84+ test "S3 uses bucket as host when both virtual_host and bucket_as_host are true" do
85+ config = ExAws.Config . new ( :s3 ) |> Map . put ( :virtual_host , true ) |> Map . put ( :bucket_as_host , true )
86+ operation = s3_operation ( "my-custom-domain.com" )
87+
88+ { processed_operation , processed_config } = S3 . add_bucket_to_path ( operation , config )
89+
90+ assert ( processed_config . host == "my-custom-domain.com" )
91+ assert ( processed_operation . path == "/folder" )
92+ end
93+
94+ test "S3 uses standard virtual host when virtual_host is true but bucket_as_host is false" do
95+ config = ExAws.Config . new ( :s3 ) |> Map . put ( :virtual_host , true ) |> Map . put ( :bucket_as_host , false )
96+ operation = s3_operation ( )
97+
98+ { processed_operation , processed_config } = S3 . add_bucket_to_path ( operation , config )
99+
100+ assert ( processed_config . host == "#{ operation . bucket } .#{ ExAws.Config . new ( :s3 ) . host } " )
101+ assert ( processed_operation . path == "/folder" )
102+ end
83103end
You can’t perform that action at this time.
0 commit comments