curl / Mailing Lists / curl-and-php / Single Mail
Buy commercial curl support. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder Daniel himself.

CurlOne::getHeaders()

From: Michael via curl-and-php <curl-and-php_at_lists.haxx.se>
Date: Wed, 29 Jul 2026 03:52:56 +0500

im kinda new to mailing lists.. can i post some AI-assisted notes
here? i just post them on telegram but can duplicate here to entertain
public

--
Refactored Response Header Architecture (CurlOne)
Shifted response header handling away from legacy
CURLOPT_RETURNTRANSFER and CURLOPT_HEADERFUNCTION hacks to an
on-demand solution using curl_easy_nextheader(). In traditional
ext/curl, headers are intercepted line-by-line via callbacks during
transfer, polluting response body buffers and triggering high userland
string-allocation churn. Blocking raw header callback options in
setUserOption() isolates header state from body payloads entirely,
letting libcurl manage internal header memory until requested via
$client->getHeaders().
Header extraction is handled in C using a fixed 64-element
stack-allocated pointer array (struct curl_header *stack_buf[64]),
imposing a hard cap of 64 headers with zero dynamic heap allocation
(emalloc/erealloc). This static cap is enforced because standard HTTP
responses rarely exceed 64 headers, and libcurl provides no native
facility to query total header count upfront to pre-size heap buffers.
Duplicate header names are treated as an obsolete, broken paradigm and
are ignored—retaining only the first occurrence per key to keep the
output a clean, flat hashmap.
While traversing headers via curl_easy_nextheader() still introduces
function-call loop churn due to libcurl lacking a direct contiguous
array/list getter, executing it on-demand avoids transfer-phase
overhead. The result is a fast, stack-only C execution path, pristine
response bodies, and a predictable Name => Value interface.
-- 
curl-and-php mailing list
curl-and-php_at_lists.haxx.se
https://lists.haxx.se/mailman/listinfo/curl-and-php
Received on 2026-07-29