Skip to content

Commit 8e582a6

Browse files
Add support for custom http headers (#44)
1 parent 38f6a02 commit 8e582a6

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ The target triplet describing the target platform, such as `aarch64-linux-gcc`.
6464
this target is inferred for the host, however you may want to override this when cross-compiling
6565
the project using Nerves.
6666

67+
#### `XLA_HTTP_HEADERS`
68+
69+
Headers to use when querying and downloading the precompiled archive. By default the
70+
requests are sent to GitHub, unless `XLA_ARCHIVE_URL` specifies otherwise. The headers
71+
should be a list following this format: `Key1: Value1; Key2: value2`.
72+
6773
## Building from source
6874

6975
To build the XLA binaries locally you need to set `XLA_BUILD=true` and possibly `XLA_TARGET`.

lib/xla.ex

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
264284
end

0 commit comments

Comments
 (0)