Skip to content

rtk curl drops the request body passed on stdin (-d @-) #4084

Closed

Description

@log0u7

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.log

Actual 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

  1. added
    bug
    good first issue
    on Sep 15, 2026
  2. rtk-wshm-sync-bot commented on Sep 15, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 97%

    Summary

    rtk curl spawns curl via Command::output() without inheriting stdin, so -d @-/-T -/--data-binary @- bodies read from a pipe are silently dropped (Content-Length: 0); fix by adding cmd.stdin(std::process::Stdio::inherit()) in curl_cmd.rs, mirroring the existing inherit_stdin() pattern used by npm_cmd.rs/wc_cmd.rs.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/cmds/cloud/curl_cmd.rs
    • src/core/runner.rs

    Triaged automatically by wshm · This is an automated analysis, not a human review.

  3. added a commit that references this issue on Oct 1, 2026
    72bc926
  4. added a commit that references this issue on Oct 3, 2026
    3fd7fc8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:clibuggood first issuepriority:high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions