cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: FR - showing body when run "curl -f"

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Wed, 2 Mar 2016 17:48:29 +0100 (CET)

On Tue, 1 Mar 2016, Alexey Melezhik wrote:

> I know how curl -f acts, and I know how curl -w acts as well. But both cases
> are not good, easy to use for me.

Yet we're talking about a mere 4 lines shell script. I can be made with
something like:

num=`curl $URL -o dump -w '%{response_code}'`
if test "$num" -ge "400"; then
   exit 1
fi

> I need behavior like with curl -f , meaning correct exit code and in
> case I handle this - immediate break of my script. But I still need a
> body. Many modern rest API, web applications return vital information
> via body when return none successful http code. curl -s -o /dev/null
> -w "%{http_code}\n" is possible workaround but it still requires
> additional bash code to verify http status which is neither convenient
> nor good code style , I try to avoid such bash-isms which eventually
> make code hard to maintain.

It's not "bashism" (it uses plain old shell), It depends on HTTP response
codes and curl functionality, which you already said you were fine with. The
upside is that it works already today and it works with very old curl versions
too without a new feature you want to add.

> I need a curl -f behavior plus http body at output, you don't have to
> change current implementation, we may talk about additional flag ,
> something like --with-body or whatever proper for you. Is this a big
> deal ?

New options need to be tested, documented and maintained for all eternety. Yes
it is a big deal and I need all new options to have a really strong
motivation. I don't think this is a very strong argument.

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-users
FAQ:        https://curl.haxx.se/docs/faq.html
Etiquette:  https://curl.haxx.se/mail/etiquette.html
Received on 2016-03-02