SkillPilotAI

curl (3/3)

Part 3 of curl: the options added after curl 8.6 (as in current Windows curl.exe), the --no- / re-enable forms, all 67 write-out (-w) variables for status and timing, the environment variables curl reads (proxies, CA bundle, config home), and which --no- boolean forms exist. This is what makes curl reliable inside scripts and CI.

165.1 Why is it used?

  • -w variables print status, sizes and per-stage timings, so you can see exactly where a slow request spends time.
  • %{onerror} prints a message only on failure: clean script logs.
  • --no-X turns off an option set earlier (e.g. in .curlrc); the last option wins.
  • Environment variables (http_proxy, NO_PROXY, CURL_CA_BUNDLE, CURL_HOME) change curl behaviour without editing commands.
  • New options (--follow, --skip-existing, --ip-tos...) need a recent curl: check with curl -V.

165.2 How it works

  • One HTTPS request has stages: DNS lookup -> TCP connect -> TLS handshake -> request sent -> first byte -> done.
  • curl records a timer at each stage, cumulative from the start; -w prints them after the response.
  • Difference of two timers = time of that stage (e.g. starttransfer - appconnect = server time).
  • Lab: client 192.168.185.20, srv.lab = 192.168.185.10 (HTTP 80, HTTPS 443 with a lab CA, proxy stub 3128).
curl request: DNS, TCP, TLS, HTTP and the -w timers
  1. 1.curl resolves srv.lab -> 192.168.185.10: time_namelookup 0.000313 s

  2. 2.TCP SYN / SYN-ACK / ACK done: time_connect 0.000600 s

  3. 3.TLS handshake finished: time_appconnect 0.018578 s

  4. 4.GET /hello sent, first byte back: time_starttransfer 0.058760 s

  5. 5.Body received: time_total 0.058866 s

starttransfer - appconnect = about 40 ms of server time in this run

165.3 New options (curl 8.6+ / Windows curl.exe)

  • Windows curl.exe 8.21.0 (Schannel) lists all 17 new options; netshoot curl 8.7.1 says "--follow: is unknown" (exit 2).
  • Alpine 3.20 curl 8.14.1 knows 12 of them, Alpine edge curl 8.23.0 knows all 17.
  • --follow follows redirects per spec (POST becomes GET on 302); -L with -X POST keeps POST.
  • --show-headers = new name of -i; --skip-existing skips the download if the local file exists; --out-null discards the body.
  • --ip-tos CS1 sets IP TOS (SYN tos 0x0 became 0x20); --parallel-max-host 2 limits parallel connections per host.
Terminal
C:\> curl.exe --versioncurl --follow http://srv.lab/acurl -s -X POST -d 'x=1' -L http://srv.lab/post-302curl -s -X POST -d 'x=1' --follow http://srv.lab/post-302curl -v --skip-existing -O http://srv.lab/file.zip 2>&1 | grep -iE 'skip|exists'
Output
C:\> curl.exe --versioncurl 8.21.0 (Windows) libcurl/8.21.0 Schannel zlib/1.3.2 WinIDN WinLDAPRelease-Date: 2026-06-24$ curl --follow http://srv.lab/acurl: option --follow: is unknowncurl: try 'curl --help' or 'curl --manual' for more information(exit 2)$ curl -s -X POST -d 'x=1' -L http://srv.lab/post-302{"method": "POST", "path": "/echo", "query": {}, "content_type": null, "accept": "*/*", "body": ""}$ curl -s -X POST -d 'x=1' --follow http://srv.lab/post-302{"method": "GET", "path": "/echo", "query": {}, "content_type": null, "accept": "*/*", "body": ""}$ curl -v --skip-existing -O http://srv.lab/file.zip 2>&1 | grep -iE 'skip|exists'Note: skips transfer, "file.zip" exists locally
Terminal
curl -s --ip-tos CS1 -o /dev/null -w '%{http_code}\n' http://srv.lab/hellocurl -s -Z --parallel-max-host 2 -o /dev/null -o /dev/null -o /dev/null -w '%{urlnum} %{conn_id}\n' http://srv.lab/hello http://srv.lab/hello http://srv.lab/hello
Output
[srv]$ tcpdump -nn -v -c 2 -i eth0 'tcp dst port 80 and ...'IP (tos 0x0, ttl 64, id 58721, offset 0, flags [DF], proto TCP (6), length 60)    192.168.185.20.39942 > 192.168.185.10.80: Flags [S]IP (tos 0x20, ttl 64, id 63525, offset 0, flags [DF], proto TCP (6), length 60)    192.168.185.20.39954 > 192.168.185.10.80: Flags [S]$ curl -s -Z --parallel-max-host 2 ... -w '%{urlnum} %{conn_id}\n' ...0 02 11 0
New optionLab result / meaning
--sigalgs rsa_pss_rsae_sha256200 OK (RSA certificate)
--sigalgs ecdsa_secp256r1_sha256exit 35 (cert is RSA)
--ech true / --ssl-sessions f"installed libcurl version does not support this"
--tls-earlydataAllow TLS 1.3 0-RTT
--vlan-priority 5VLAN priority (200 OK)
--keepalive-cnt 3Max keepalive probes
--proxy-http3 / --knownhosts / --upload-flagsHTTP/3 to proxy / SSH known_hosts / IMAP flags (not run)
--mptcpMultipath TCP (not run: kernel has no MPTCP)

165.4 Negated and re-enable forms

  • Any boolean option can be turned off with --no-<option>; the later option wins.
  • -L --no-location gives the 302 itself (useful to cancel a -L from .curlrc).
  • --no-progress-meter hides only the meter; -s --no-silent brings the meter back.
  • Re-enable forms bring back defaults a config turned off: --buffer, --keepalive, --alpn, --sessionid, --epsv, --eprt, --clobber.
  • --no-alpn removes the ALPN offer (TLS 1.3 still works); --no-npn changes nothing (curl has no NPN any more).
  • --no-sessionid stops TLS session reuse; --no-keepalive turns off TCP keepalive probes only (connection reuse still happens).
Terminal
curl -s -L --no-location -o /dev/null -w '%{http_code} %{url_effective}\n' http://srv.lab/acurl -s -L -o /dev/null -w '%{http_code} %{url_effective}\n' http://srv.lab/acurl -sv --cacert /tmp/ca.crt -o /dev/null https://srv.lab/hello 2>&1 | grep -E 'ALPN|SSL connection|HTTP/'
Output
$ curl -s -L --no-location -o /dev/null -w '...' http://srv.lab/a302 http://srv.lab/a$ curl -s -L -o /dev/null -w '...' http://srv.lab/a200 http://srv.lab/hello$ curl -sv --cacert /tmp/ca.crt ... | grep -E 'ALPN|SSL connection|HTTP/'* ALPN: curl offers h2,http/1.1* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384 / x25519 / RSASSA-PSS* ALPN: server accepted http/1.1* using HTTP/1.x> GET /hello HTTP/1.1< HTTP/1.1 200 OK

165.5 Write-out (-w) variables

  • -w 'format' prints after the response; variables are %{name}. Keep long formats in a file: -w @file.
  • Script favourites: %{http_code}, %{size_download}, %{remote_ip}, %{num_redirects}, %{url_effective}, %{redirect_url}.
  • %{json} prints all variables as one JSON object; %{header_json} gives every header as an array (both Set-Cookie values).
  • %{onerror} prints the rest only on failure; %{exitcode} and %{errormsg} explain it.
  • %{stderr} / %{stdout} switch streams; %output{file} writes the rest to a file; %header{name} prints one header.
Terminal
cat /lab/timing.fmtcurl -s -o /dev/null --cacert /tmp/ca.crt -w @/lab/timing.fmt https://srv.lab/hellocurl -s -L -o /dev/null -w '%{num_redirects} redirects, final %{url_effective}\n' http://srv.lab/acurl -s -o /dev/null -w '%{http_code} goes to %{redirect_url}\n' http://srv.lab/a
Output
$ cat /lab/timing.fmt   dns: %{time_namelookup}s\n   tcp: %{time_connect}s\n   tls: %{time_appconnect}s\n  ttfb: %{time_starttransfer}s\n total: %{time_total}s\n$ curl -s -o /dev/null --cacert /tmp/ca.crt -w @/lab/timing.fmt https://srv.lab/hello   dns: 0.000313s   tcp: 0.000600s   tls: 0.018578s  ttfb: 0.058760s total: 0.058866s$ curl -s -L -o /dev/null -w '...' http://srv.lab/a2 redirects, final http://srv.lab/hello$ curl -s -o /dev/null -w '...' http://srv.lab/a302 goes to http://srv.lab/old
Terminal
curl -s -o /dev/null -w '%{json}' http://srv.lab/hello | jq '{http_code, method, http_version, remote_ip, remote_port, local_ip, num_connects, num_headers, content_type, exitcode}'curl -s -f -o /dev/null -w '%{onerror}FAILED %{exitcode}: %{errormsg}\n' http://srv.lab/missingcurl -s -o /dev/null -w '%{onerror}FAILED %{exitcode}: %{errormsg}\n' http://192.168.185.10:81/
Output
{  "http_code": 200,  "method": "GET",  "http_version": "1.1",  "remote_ip": "192.168.185.10",  "remote_port": 80,  "local_ip": "192.168.185.20",  "num_connects": 1,  "num_headers": 6,  "content_type": "text/plain",  "exitcode": 0}$ curl -s -f -o /dev/null -w '%{onerror}...' http://srv.lab/missingFAILED 22: The requested URL returned error: 404$ curl -s -o /dev/null -w '%{onerror}...' http://192.168.185.10:81/FAILED 7: Failed to connect to 192.168.185.10 port 81 after 15 ms: Couldn't connect to server
GroupVariables
Responsehttp_code / response_code, http_version, method, content_type, num_headers, http_connect (proxy CONNECT code)
Connectionremote_ip, remote_port, local_ip, local_port, num_connects, scheme
Sizes and speedsize_download, size_upload, size_header, size_request, speed_download, speed_upload
Timers (seconds)time_namelookup, time_connect, time_appconnect, time_pretransfer, time_starttransfer, time_redirect, time_total
Redirects and URLnum_redirects, redirect_url, url, url_effective, urlnum, url.host / urle.host ... (8.1+)
TLSssl_verify_result (0 = OK), proxy_ssl_verify_result, certs, num_certs
Errors and outputexitcode, errormsg, onerror, stderr, stdout, json, header_json, %header{name}, %output{file}

165.6 Environment variables

  • http_proxy (lower case only) sends HTTP requests to the proxy; HTTP_PROXY upper case is ignored by curl.
  • HTTPS_PROXY makes curl send CONNECT first; NO_PROXY=srv.lab goes direct; ALL_PROXY is the fallback.
  • CURL_CA_BUNDLE / SSL_CERT_FILE set the default CA file (exit 60 -> 0); SSLKEYLOGFILE writes TLS secrets for Wireshark.
  • .curlrc is searched in CURL_HOME > XDG_CONFIG_HOME > HOME (Windows: USERPROFILE / APPDATA, _curlrc); -q skips it.
  • Windows: CMD set N=v, PowerShell $env:N="v".
Proxy environment variables
  1. 1.http_proxy=http://192.168.185.10:3128 curl http://srv.lab/hello

  2. 2.Request GET http://srv.lab/hello goes to the proxy stub, not the server

  3. 3.HTTPS_PROXY set: curl sends CONNECT srv.lab:443 to the stub

  4. 4.Stub replies 200 Connection established, TLS runs inside the tunnel

  5. 5.NO_PROXY=srv.lab: the request goes direct to 192.168.185.10

Terminal
cat /tmp/ch/.curlrcCURL_HOME=/tmp/ch curl -o /dev/null http://srv.lab/aCURL_HOME=/tmp/ch curl -q -s -o /dev/null -w '%{http_code}\n' http://srv.lab/ahttp_proxy=http://192.168.185.10:3128 curl -s http://srv.lab/helloHTTP_PROXY=http://192.168.185.10:3128 curl -s http://srv.lab/hellocurl -s -o /dev/null -w '%{exitcode} %{errormsg}\n' https://srv.lab/helloCURL_CA_BUNDLE=/tmp/ca.crt curl -s -o /dev/null -w '%{exitcode} %{ssl_verify_result}\n' https://srv.lab/hello
Output
$ cat /tmp/ch/.curlrclocationsilentwrite-out = "%{http_code} %{url_effective}\n"$ CURL_HOME=/tmp/ch curl -o /dev/null http://srv.lab/a200 http://srv.lab/hello$ CURL_HOME=/tmp/ch curl -q -s -o /dev/null -w '%{http_code}\n' http://srv.lab/a302$ http_proxy=... curl -s http://srv.lab/helloproxy stub got: GET http://srv.lab/hello (not forwarded)$ HTTP_PROXY=... curl -s http://srv.lab/hellohello from n165-srv$ curl -s -o /dev/null -w '%{exitcode} %{errormsg}\n' https://srv.lab/hello60 SSL certificate problem: unable to get local issuer certificate$ CURL_CA_BUNDLE=/tmp/ca.crt curl -s ...0 0

165.7 Negated boolean options (--no-...)

  • All 87 --no- forms from the PDF were run against file:///etc/hostname with no network: 78 exit 0, 9 exit 2.
  • The 9 failures take a value, so they are not booleans: --no-cert, --no-ftp-ssl-ccc-mode, --no-http2, --no-http2-prior-knowledge, --no-mail-rcpt, --no-proxy, --no-retry, --no-socks5, --no-trace.
  • Useful ones: --no-insecure (verify on again), --no-fail, --no-get, --no-head, --no-include, --no-verbose, --no-silent, --no-progress-bar, --no-netrc.
  • --no-proxy does not exist; to skip a proxy use --noproxy hosts.
Terminal
for o in $(cat /lab/no87.txt); do  out=$(curl -s --no-$o -o /dev/null file:///etc/hostname 2>&1; echo "exit $?")  printf '%-30s %s\n' "--no-$o" "$(echo $out)"donesh /lab/lab-no87.sh | grep -c "exit 0$"
Output
$ sh /lab/lab-no87.sh | grep -c "exit 0$"78$ sh /lab/lab-no87.sh | grep -v "exit 0$"--no-cert   ... isn't a boolean ... exit 2--no-ftp-ssl-ccc-mode  ... exit 2curl: option --no-http2: used '--no-' for option that isn't a boolean curl: try 'curl --help' or 'curl --manual' for more information exit 2--no-http2-prior-knowledge  ... exit 2--no-mail-rcpt  ... exit 2--no-proxy  ... exit 2--no-retry  ... exit 2--no-socks5  ... exit 2--no-trace  ... exit 2

165.8 Common mistakes

  • Assuming an option listed in --help works: curl 8.23 lists --ech and --ssl-sessions but its libcurl does not support them; check curl -V features.
  • Setting HTTP_PROXY in upper case for curl: only lower-case http_proxy is used for HTTP.
  • Reading time_total as server time: subtract appconnect from starttransfer.
  • Expecting --no-keepalive to stop connection reuse: it only disables TCP keepalive probes.
  • Writing --no-http2 or --no-proxy: value options have no --no- form.

165.9 Interview tips

  • Slow API: print five timers (namelookup, connect, appconnect, starttransfer, total); the difference shows the slow stage.
  • Keep the format in a file and reuse it: -w @timing.fmt.
  • Message only on failure: -w '%{onerror}FAILED %{exitcode}: %{errormsg}\n'.
  • -L vs --follow: -L with -X POST keeps POST after a redirect, --follow switches to GET per spec.