Repository navigation
feat(curl): support -I/--head to fetch headers only - #209
Conversation
876c6e3 to
33c94aa
Compare
|
@strandly-the-agent Please review this PR |
strandly-the-agent
left a comment
There was a problem hiding this comment.
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 againstorigin/main: the 6 newcurl_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-Lengthon HEAD. Nothing hung. That produced 24 divergences: 2 root causes come from this PR (A1 inline, A2 below); the rest are pre-existing onmainor come from options the builtin doesn't support. - I didn't run
cargo fmtor 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 GETstill downloads the whole body and then drops it (:641). A body overmax_outputfails with(6) response body too large, and a slow body hits-mwith(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 -owriting headers to the file (:614-617). I checked it by hand: a 135-byte file and exit 22, the same as real curl. - ⚪
:614-621repeats the stdout-or--owrite 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. -fwithout-sprints no(22)message, because:622checks onlyshow_error. The other error paths check(!silent || show_error).-vdoesn'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
-Iwith-F,-T,--data-binary,--data-urlencodeor-Ggivesinvalid option(exit 1), because the builtin doesn't support those options.
|
@strandly-the-agent Please review this PR Updated to 6ee5a2f with the redirect-error fix and regression coverage for stdout and I kept |
strandly-the-agent
left a comment
There was a problem hiding this comment.
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 noreturnis left inside the loop. - Fix checked for side effects: without
-I,hop_headersis always empty, so nothing changes. The-woutput 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_failsandcurl_redirect_to_blocked_ip_denied. They cover stdout and-o. The-I -f -otest gap is closed too. - Thanks for clarifying the
-i -Lscope and for documenting the-I -X GETlimitation; both are settled for me.
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
-Isends 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-Xstill picks the method, while-i -Loutput and redirect policy stay unchanged to keep this focused on HEAD support. One limit remains:-I -X GETdownloads 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.
cargo test --workspace --all-targets,pytest tests/python,npm test)cargo fmtandcargo clippyChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.