Skip to content

tool: append buffered response headers in constant time - #23352

Closed
cla7aye15I4nd wants to merge 8 commits into
curl:masterfrom
cla7aye15I4nd:zheng/curl-header-append
Closed

cla7aye15I4nd wants to merge 8 commits into
curl:masterfrom
cla7aye15I4nd:zheng/curl-header-append

Conversation

@cla7aye15I4nd

@cla7aye15I4nd cla7aye15I4nd commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

With -OJ --show-headers, buffering each response header walks the existing curl_slist, making construction quadratic. Reuse the tool's slist_wc wrapper to append in constant time while retaining received order. Make the wrapper available when CURL_DISABLE_LIBCURL_OPTION is enabled, and release it on flush, error and transfer cleanup.

Validation: normal debug build and a build with CURL_DISABLE_LIBCURL_OPTION=ON and CURL_DISABLE_HEADERS_API=ON both compile. External local-server checks compare the complete output bytes for ordinary headers, repeated headers, a 100 Continue response, a late Content-Disposition filename and a 4,000-header response with a body; all three cases pass in both configurations. Existing --libcurl tests 1400-1405 pass. Test 4657 was skipped by the local test runner. Source-format and whitespace checks pass.

The earlier constant-time implementation measured 20k/40k/60k short headers at approximately 22/24/26 ms versus 177/662/1451 ms before the patch; the current implementation uses the existing cached-tail abstraction for the same algorithm.

@cla7aye15I4nd cla7aye15I4nd changed the title tool: append buffered response headers in constant time [WIP] tool: append buffered response headers in constant time Oct 11, 2026
@cla7aye15I4nd cla7aye15I4nd changed the title [WIP] tool: append buffered response headers in constant time tool: append buffered response headers in constant time Oct 11, 2026
@cla7aye15I4nd
cla7aye15I4nd marked this pull request as ready for review October 11, 2026 08:01
@bagder
bagder requested a balanced review from Copilot October 11, 2026 21:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The changes preserve ordering and cleanup semantics while eliminating repeated list traversal.

0 open findings

What changed in this PR

Optimizes buffered response-header appends from quadratic to constant time.

Changes:

  • Uses slist_wc cached-tail lists for buffered headers.
  • Ensures cleanup across flush, failure, and transfer completion.
  • Makes slist_wc available without --libcurl support.
File Description
src/​tool_operate.c Frees the wrapped header list during cleanup.
src/​tool_cb_hdr.h Changes buffered-header storage to slist_wc.
src/​tool_cb_hdr.c Appends and flushes headers through the wrapper.
src/​slist_wc.h Exposes the wrapper for all configurations.
src/​slist_wc.c Builds the wrapper implementation unconditionally.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions github-actions Bot added the CI Continuous Integration label Oct 13, 2026
@cla7aye15I4nd
cla7aye15I4nd marked this pull request as draft October 15, 2026 05:28
@cla7aye15I4nd cla7aye15I4nd changed the title tool: append buffered response headers in constant time [DONE] tool: append buffered response headers in constant time Oct 15, 2026
@cla7aye15I4nd cla7aye15I4nd changed the title [DONE] tool: append buffered response headers in constant time tool: append buffered response headers in constant time Oct 15, 2026
@cla7aye15I4nd
cla7aye15I4nd marked this pull request as ready for review October 15, 2026 06:37
@cla7aye15I4nd
cla7aye15I4nd marked this pull request as draft October 15, 2026 07:41
@cla7aye15I4nd cla7aye15I4nd changed the title tool: append buffered response headers in constant time [DONE] tool: append buffered response headers in constant time Oct 15, 2026
@cla7aye15I4nd
cla7aye15I4nd marked this pull request as ready for review October 15, 2026 07:52
@cla7aye15I4nd cla7aye15I4nd changed the title [DONE] tool: append buffered response headers in constant time tool: append buffered response headers in constant time Oct 15, 2026
@cla7aye15I4nd
cla7aye15I4nd marked this pull request as draft October 15, 2026 08:41
@cla7aye15I4nd cla7aye15I4nd changed the title tool: append buffered response headers in constant time [DONE] tool: append buffered response headers in constant time Oct 15, 2026
@cla7aye15I4nd
cla7aye15I4nd marked this pull request as ready for review October 15, 2026 17:41
@cla7aye15I4nd cla7aye15I4nd changed the title [DONE] tool: append buffered response headers in constant time tool: append buffered response headers in constant time Oct 15, 2026
@bagder bagder closed this in 2910040 Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Continuous Integration cmdline tool

Development

Successfully merging this pull request may close these issues.

2 participants