From 946f00f3821f89b1f979992e98775bac63b42ccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?George=20Guimar=C3=A3es?= Date: Sat, 24 Oct 2026 09:12:21 -0300 Subject: [PATCH] Raise httpc's header limit for NIF downloads Since 2026-10-23, GitHub release-download redirects send about 11 KB of response headers. :httpc accepts 10 KB by default, so the download fails with {:header_too_long, {:max, 10240}}. This change sets max_header_size to 65_536, the same value as the fixes in rustler_precompiled, elixir_make and xla. --- CHANGELOG.md | 4 ++++ lib/zigler_precompiled.ex | 3 ++- test/download_test.exs | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) 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")