Skip to content

feat(curl): support -I/--head to fetch headers only - #209

Merged
ferdingler merged 2 commits into
strands-agents:mainfrom
ferdingler:feat/curl-head
Nov 12, 2026
Merged

ferdingler merged 2 commits into
strands-agents:mainfrom
ferdingler:feat/curl-head

Conversation

@ferdingler

@ferdingler ferdingler commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Description

curl -I (or --head) was rejected as an unknown option. That's a common way to check whether a URL is up or where it redirects without downloading the body.

Now -I sends HEAD and prints headers, including redirect hops received before a later failure, with the existing silent, output-file, write-out and fail options. An explicit -X still picks the method, while -i -L output and redirect policy stay unchanged to keep this focused on HEAD support. One limit remains: -I -X GET downloads the body before hiding it, so body limits and timeouts still apply.

I compared successful requests and redirect failures against real curl, and added checks for headers surviving refused, blocked and timed-out requests, both on stdout and in an output file. The new error-path tests fail before the fix and pass after it; the full local Rust suite, doc tests, formatting, clippy and docs checks pass.

Related Issues

Part of #207

Documentation PR

N/A

Type of Change

New feature

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce new warnings.

  • I ran the relevant test suites for the bindings I touched (cargo test --workspace --all-targets, pytest tests/python, npm test)
  • If I touched Rust, I ran cargo fmt and cargo clippy

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ferdingler
ferdingler marked this pull request as ready for review November 12, 2026 19:31
@ferdingler
ferdingler requested a review from a team as a code owner November 12, 2026 19:31
@ferdingler

Copy link
Copy Markdown
Collaborator Author

@strandly-the-agent Please review this PR

@strandly-the-agent strandly-the-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verdict: approve, with one should-fix. I compared -I against real curl 7.88.1 for every combination the PR claims (-s, -o, -w, -f, -L, -X, and -I -d exiting 2), and it matches. The 6 new tests fail on main and pass here (66/66 in curl_integration).

🟡 -I -L drops the headers from earlier hops when a later hop fails. Real curl prints them before it errors. Details and a fix are in the inline comment.

The only new surface is a CLI flag plus one HELP line, so it doesn't need needs-api-review.

✅ What I verified, plus routing, questions and appendix

Verified (head 33c94aa)

  • cargo test --test curl_integration: 66 passed. I also ran the PR's test file against origin/main: the 6 new curl_head_flag_* tests fail and the other 60 pass.
  • About 75 probe cases, each run through both real curl 7.88.1 and the builtin against a local HTTP/1.1 server that sends Content-Length on HEAD. Nothing hung. That produced 24 divergences: 2 root causes come from this PR (A1 inline, A2 below); the rest are pre-existing on main or come from options the builtin doesn't support.
  • I didn't run cargo fmt or clippy because rustfmt isn't in the sandbox toolchain.

Routing. Two passes ran: a correctness/tests reviewer, because this is a logic change, and an adversarial pass, because it touches flag parsing, the redirect loop and error paths, and real curl is available to compare against. I skipped the API/DevX pass because no Rust, Python or TS API changed. The first adversarial run (advanced tier) timed out at 900s after finishing its probes and before writing its report. A second run (default tier) sorted its 24 divergences into introduced and pre-existing, checking against main.

Question (non-blocking). Real curl -i -L also prints every hop's headers. Using if include instead of if head at curl.rs:499/:581 would match curl for both flags. You kept -i -L as it is on purpose. Was that to avoid conflicts with #144, or for a behaviour reason?

Reading order: curl.rs:308-331 (flag and the -d conflict) → :496-501 / :578-583 (hop collection) → :601-641 (output and -f paths) → tests.

Appendix: non-blocking (3)

  • ⚪ A2: -I -X GET still downloads the whole body and then drops it (:641). A body over max_output fails with (6) response body too large, and a slow body hits -m with (28). Real curl reads no body here, so it exits 0. The cause is in the kernel's body read (src/vfs_kernel.rs:897), so listing it as a known limitation is fine.
  • ⚪ No test covers -I -f -o writing headers to the file (:614-617). I checked it by hand: a 135-byte file and exit 22, the same as real curl.
  • ⚪ :614-621 repeats the stdout-or--o write that is already at :643-655.

Pre-existing on main, not caused by this PR (not filed)

  • When the redirect limit runs out, the builtin exits 0 with the last 3xx. Real curl exits (47). The builtin's limit is a fixed 10 (:335); real curl's default is 50. I can file this if you want it tracked.
  • -f without -s prints no (22) message, because :622 checks only show_error. The other error paths check (!silent || show_error).
  • -v doesn't echo < response headers to stderr. Header names come out lowercase (vfs_kernel.rs:885). All non-timeout transport errors map to (6), where curl uses (7) for a refused connection.
  • Combining -I with -F, -T, --data-binary, --data-urlencode or -G gives invalid option (exit 1), because the builtin doesn't support those options.

Comment thread src/commands/curl.rs Resolved
@ferdingler

Copy link
Copy Markdown
Collaborator Author

@strandly-the-agent Please review this PR

Updated to 6ee5a2f with the redirect-error fix and regression coverage for stdout and -o, including the missing -I -f -o case. All 68 curl integration tests and the full local Rust checks pass.

I kept -i -L unchanged to keep this PR focused on adding HEAD support and avoid mixing in a separate change to existing output behavior; it wasn't a claim that the current behavior matches real curl. I also added the -I -X GET body-download limitation to the description, since fixing that requires changing the request/kernel behavior.

@strandly-the-agent strandly-the-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verdict: approve. 6ee5a2f fixes the 🟡 from my last review: headers from earlier redirect hops now survive a failed later hop. I found nothing new.

  • Previous finding (fixed): all 7 error exits in the redirect loop now break Err(code) and share one flush path (curl.rs:571-600). I checked that no return is left inside the loop.
  • Fix checked for side effects: without -I, hop_headers is always empty, so nothing changes. The -w output on timeout still prints and now comes after the headers, which is the order real curl uses.
  • Tests: 68/68 pass in curl_integration. With the old code (33c94aa) and the new tests, 3 fail: …keeps_headers_when_a_later_hop_fails, …when_a_redirect_connection_fails and curl_redirect_to_blocked_ip_denied. They cover stdout and -o. The -I -f -o test gap is closed too.
  • Thanks for clarifying the -i -L scope and for documenting the -I -X GET limitation; both are settled for me.

@ferdingler
ferdingler merged commit 90d9284 into strands-agents:main Nov 12, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants