httpie / cli

🥧 HTTPie CLI — modern, user-friendly command-line HTTP client for the API era. JSON support, colors, sessions, downloads, plugins & more.
https://httpie.io
BSD 3-Clause "New" or "Revised" License
32.71k stars 3.67k forks source link

Display a warning for using option --ignore-stdin when request fails with content present in stdin #1525

Open landure opened 10 months ago

landure commented 10 months ago

Checklist


Running environment

Minimal reproduction code and steps

Install the software:

sudo apt install 'miller' jq'

The error occurred when interrogating Gandi Public API.

Set Gandi API Key:

gandi_api_key="<Gandi API key>"

Query Gandi API for all domains mailboxes:

while read -r 'domain'; do
  command https --body "https://api.gandi.net/v5/email/mailboxes/${domain}" \
    "Authorization: Apikey ${gandi_api_key}" 'per_page==250'
done < <( command https --body 'https://api.gandi.net/v5/domain/domains' \
    "Authorization: Apikey ${gandi_api_key}" 'per_page==250' |
  command jq '.[].fqdn' |
  command tr --delete '"' )

Current result

The first loop output is:

Bad Request

Expected result

The expected result:

Bad Request

Warning: stdin contents detected. Retry with --ignore-stdin option.

Additional information, screenshots, or code examples

I've found the final answer in #1017 and when using --debug option. HTTPie should be able to detect if stdin contents come from a pipe or are for xargs or a bash loop. In any case, displaying a warning when a request fails with stdin content could prevent users some headaches.