Repository navigation
Description
rtk curl drops the request body passed on stdin (-d @-)
Summary
When the request body is fed to curl via stdin (-d @- with a heredoc or pipe), rtk curl sends an empty body: the server receives Content-Length: 0. The same request via -d @file works fine, and plain (unwrapped) curl -d @- works fine too.
Steps to reproduce
Echo server that logs exactly what it receives:
# /tmp/echo_server.py
import http.server
class H(http.server.BaseHTTPRequestHandler):
def do_PUT(self):
n = int(self.headers.get("Content-Length", 0) or 0)
body = self.rfile.read(n)
with open("/tmp/received.log", "ab") as f:
f.write(b"LEN=" + str(n).encode() + b" BODY=" + body + b"\n")
self.send_response(204); self.end_headers()
def log_message(self, *a): pass
http.server.HTTPServer(("127.0.0.1", 8971), H).serve_forever()rm -f /tmp/received.log
python3 /tmp/echo_server.py & sleep 1
echo '{"via":"heredoc"}' | rtk curl -sS -X PUT -H "Content-Type: application/json" -d @- http://127.0.0.1:8971/t
echo '{"via":"file"}' > /tmp/body.json
rtk curl -sS -X PUT -H "Content-Type: application/json" -d @/tmp/body.json http://127.0.0.1:8971/t
curl -sS -X PUT -H "Content-Type: application/json" -d @/tmp/body.json http://127.0.0.1:8971/t
cat /tmp/received.logActual result:
LEN=0 BODY= <- rtk curl -d @- : body lost
LEN=14 BODY={"via":"file"} <- rtk curl -d @file: OK
LEN=14 BODY={"via":"file"} <- plain curl @file : OK
Expected vs actual
- Expected:
rtk curl -d @-forwards its own stdin to curl, like plain curl does. Server receives the full body. - Actual: the child curl gets an empty (EOF) stdin and sends
Content-Length: 0.
Real-world impact: any API call built with a heredoc body, e.g. Redmine/Jira/GitHub REST updates, silently updates nothing or corrupts the payload.
Root cause analysis
src/cmds/cloud/curl_cmd.rs spawns curl with Command::output() (line ~40). Per the std docs, Command::output() gives the child an immediate-EOF stdin ("Stdin is not inherited from the parent and any attempt by the child process to read from the stdin stream will result in an immediate EOF"), so curl -d @- reads EOF instantly.
The codebase already has the fix pattern for this exact problem elsewhere: RunOptions::inherit_stdin() in src/core/runner.rs ("Forward rtk's own stdin to the child process. Needed for commands that can read from a pipe (e.g. cat file | rtk wc); without it the child gets an empty stdin and reports zero"), used by npm_cmd.rs and wc_cmd.rs via StdinMode::Inherit. curl_cmd.rs manages its own Command (for raw-byte binary passthrough), so it never got stdin forwarding.
Suggested fix is one line in curl_cmd.rs::run() before .output():
cmd.stdin(std::process::Stdio::inherit());(An explicitly configured stdin wins over output()'s default-null; stream.rs relies on the same std behavior.)
Same applies to other stdin-reading curl forms: -T -, --data-binary @-, --form -F field=@-, -K - (config from stdin).
Related (same bug class, other wrapped commands)
Flags reading stdin in other wrapped tools would hit the same EOF-stdin issue (e.g. gh api --input -, git hash-object -w --stdin). Out of scope here, but worth a look.
Activity
rtk-wshm-sync-bot commentedon Sep 15, 2026
🔍 Automated Triage
bughighSummary
rtk curlspawns curl viaCommand::output()without inheriting stdin, so-d @-/-T -/--data-binary @-bodies read from a pipe are silently dropped (Content-Length: 0); fix by addingcmd.stdin(std::process::Stdio::inherit())in curl_cmd.rs, mirroring the existinginherit_stdin()pattern used by npm_cmd.rs/wc_cmd.rs.📁 Relevant files
src/cmds/cloud/curl_cmd.rssrc/core/runner.rsTriaged automatically by wshm · This is an automated analysis, not a human review.
fix(curl): inherit stdin so -d @- / -T - / --data-binary @- work
fix(curl): forward stdin to curl so -d @- bodies are not dropped