diff --git a/CHANGELOG.md b/CHANGELOG.md index c2caf6e..fb335f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Fixed + +- Accept up to 64 KiB of response headers when downloading NIF artifacts. GitHub release redirects now send more than the 10 KiB `:httpc` allows by default. + ## 0.1.6 - 2026-09-10 ### Fixed diff --git a/lib/zigler_precompiled.ex b/lib/zigler_precompiled.ex index 768de75..a3764f7 100644 --- a/lib/zigler_precompiled.ex +++ b/lib/zigler_precompiled.ex @@ -441,7 +441,8 @@ defmodule ZiglerPrecompiled do Logger.debug("Downloading NIF from #{url}") case :httpc.request(:get, {String.to_charlist(url), request_headers}, http_options, - body_format: :binary + body_format: :binary, + max_header_size: 65_536 ) do {:ok, {{_, 200, _}, _resp_headers, body}} -> {:ok, body} diff --git a/test/download_test.exs b/test/download_test.exs index 4907f72..8b8a017 100644 --- a/test/download_test.exs +++ b/test/download_test.exs @@ -29,6 +29,28 @@ defmodule ZiglerPrecompiled.DownloadTest do assert result.checksum == "sha256:#{expected_hash}" end + test "follows a redirect whose headers exceed httpc's default limit", %{bypass: bypass} do + Bypass.expect_once(bypass, "GET", "/download/my_nif.so.tar.gz", fn conn -> + conn + |> Plug.Conn.put_resp_header("content-security-policy", String.duplicate("a", 12 * 1024)) + |> Plug.Conn.put_resp_header("location", "http://localhost:#{bypass.port}/artifact") + |> Plug.Conn.resp(302, "") + end) + + Bypass.expect_once(bypass, "GET", "/artifact", fn conn -> + Plug.Conn.resp(conn, 200, "fake nif content") + end) + + url = "http://localhost:#{bypass.port}/download/my_nif.so.tar.gz" + + assert [%{path: path}] = + ZiglerPrecompiled.download_nif_artifacts_with_checksums!([ + {"my_nif.so.tar.gz", {url, []}} + ]) + + assert File.read!(path) == "fake nif content" + end + test "raises on failure without ignore flag", %{bypass: bypass} do Bypass.expect(bypass, "GET", "/missing.so.tar.gz", fn conn -> Plug.Conn.resp(conn, 404, "not found")