@@ -16,6 +16,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
1616 sig { params ( url : String , name : String , version : T . nilable ( T . any ( String , Version ) ) , meta : T . untyped ) . void }
1717 def initialize ( url , name , version , **meta )
1818 @try_partial = T . let ( true , T ::Boolean )
19+ @expand_deferred_environment = T . let ( false , T ::Boolean )
1920 @mirrors = T . let ( meta . fetch ( :mirrors , [ ] ) , T ::Array [ String ] )
2021 @file_size = T . let ( nil , T . nilable ( Integer ) )
2122 @last_modified = T . let ( nil , T . nilable ( Time ) )
@@ -261,6 +262,20 @@ def _curl_download(resolved_url, to, timeout)
261262 curl_download resolved_url , to :, try_partial : @try_partial , timeout :
262263 end
263264
265+ sig { void }
266+ def allow_deferred_environment_expansion!
267+ @expand_deferred_environment = true
268+ end
269+
270+ sig { params ( args : T ::Array [ String ] ) . returns ( T ::Array [ String ] ) }
271+ def expand_deferred_environment_args ( args )
272+ return args unless @expand_deferred_environment
273+
274+ with_context ( deferred_environment_expansion : true ) do
275+ args . map { |arg | ENV . expand_deferred_environment ( arg ) }
276+ end
277+ end
278+
264279 # Curl options to be always passed to curl,
265280 # with raw head calls (`curl --head`) or with actual `fetch`.
266281 sig { returns ( T ::Array [ String ] ) }
@@ -273,7 +288,7 @@ def _curl_args
273288
274289 args += [ "--user" , meta . fetch ( :user ) ] if meta . key? ( :user )
275290
276- args += meta . fetch ( :headers , [ ] ) . flat_map { |h | [ "--header" , ENV . expand_deferred_environment ( h ) . strip ] }
291+ args += expand_deferred_environment_args ( meta . fetch ( :headers , [ ] ) ) . flat_map { |h | [ "--header" , h . strip ] }
277292
278293 args
279294 end
@@ -285,7 +300,7 @@ def _curl_opts
285300
286301 sig { override . params ( args : String , options : T . untyped ) . returns ( SystemCommand ::Result ) }
287302 def curl_output ( *args , **options )
288- super ( *_curl_args , *args , **_curl_opts , **options )
303+ super ( *_curl_args , *expand_deferred_environment_args ( args ) , **_curl_opts , **options )
289304 end
290305
291306 sig {
@@ -294,6 +309,6 @@ def curl_output(*args, **options)
294309 }
295310 def curl ( *args , print_stdout : true , **options )
296311 options [ :connect_timeout ] = 15 unless mirrors . empty?
297- super ( *_curl_args , *args , **_curl_opts , **command_output_options , **options )
312+ super ( *_curl_args , *expand_deferred_environment_args ( args ) , **_curl_opts , **command_output_options , **options )
298313 end
299314end
0 commit comments