@@ -229,8 +229,8 @@ defmodule XLA do
229229 defp download ( url , dest ) do
230230 command =
231231 case network_tool ( ) do
232- :curl -> "curl --fail -L #{ url } -o #{ dest } "
233- :wget -> "wget -O #{ dest } #{ url } "
232+ :curl -> "curl --fail -L -o #{ dest } #{ curl_options ( ) } #{ url } "
233+ :wget -> "wget -O #{ dest } #{ wget_options ( ) } #{ url } "
234234 end
235235
236236 case System . shell ( command ) do
@@ -242,8 +242,8 @@ defmodule XLA do
242242 defp get ( url ) do
243243 command =
244244 case network_tool ( ) do
245- :curl -> "curl --fail --silent -L #{ url } "
246- :wget -> "wget -q -O - #{ url } "
245+ :curl -> "curl --fail --silent -L #{ curl_options ( ) } #{ url } "
246+ :wget -> "wget -q -O - #{ wget_options ( ) } #{ url } "
247247 end
248248
249249 case System . shell ( command ) do
@@ -261,4 +261,24 @@ defmodule XLA do
261261 end
262262
263263 defp executable_exists? ( name ) , do: System . find_executable ( name ) != nil
264+
265+ defp http_headers ( ) do
266+ if headers = System . get_env ( "XLA_HTTP_HEADERS" ) do
267+ headers
268+ |> String . split ( ";" , trim: true )
269+ |> Enum . map ( & String . trim / 1 )
270+ else
271+ [ ]
272+ end
273+ end
274+
275+ defp curl_options ( ) do
276+ headers = http_headers ( )
277+ Enum . map_join ( headers , " " , & "-H '#{ & 1 } '" )
278+ end
279+
280+ defp wget_options ( ) do
281+ headers = http_headers ( )
282+ Enum . map_join ( headers , " " , & "--header='#{ & 1 } '" )
283+ end
264284end
0 commit comments