Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use of --fail hides http headers/body #1978

Closed
lexinator opened this issue Oct 10, 2017 · 7 comments
Closed

use of --fail hides http headers/body #1978

lexinator opened this issue Oct 10, 2017 · 7 comments

Comments

@lexinator
Copy link

lexinator commented Oct 10, 2017

I did this

% curl --fail --dump-header - --request POST --data-urlencode foo=bar 127.0.0.1:9999
curl: (22) The requested URL returned error: 403 Forbidden
% echo $?
22

I expected the following

% curl --fail --dump-header - --request POST --data-urlencode foo=bar 127.0.0.1:9999
HTTP/1.0 403 Forbidden
Server: foo/1.0
Date: Tue, 10 Oct 2017 16:36:03 GMT
Content-type: text/html

<html><body><h1>POST!</h1></body></html>

%echo $?
22

curl/libcurl version

[curl -V output]

% curl -V
curl 7.54.0 (x86_64-apple-darwin16.0) libcurl/7.54.0 SecureTransport zlib/1.2.8
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz UnixSockets

operating system

% uname -a
Darwin sequel 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64
@bagder
Copy link
Member

bagder commented Oct 10, 2017

You're actually using and experiencing --fail exactly as it is intended to work, how it is documented to work and how it has worked since its introduction some 15 years ago.

@lexinator
Copy link
Author

ok i guess that means I'm requesting a new option that behaves like this?

@jay
Copy link
Member

jay commented Oct 11, 2017

What's your use case? You could use --write-out to save the http code in a variable, which is easy as long as you are redirecting the server output somewhere. If you want server output to go directly to stdout then I think you'd have to open a separate file descriptor like this.

@lexinator
Copy link
Author

my use case is to capture the http body and have a non zero exit code for non 2xx status codes.

thanks for the tip/link as that seems like the path I'll have to go down if I want to do this with existing curl version.

@jay jay closed this as completed Oct 13, 2017
@lexinator
Copy link
Author

so i guess that means i don’t get a new flag doing the more straight forward solution?

@bagder
Copy link
Member

bagder commented Oct 16, 2017

No, I find it very hard to motivate a new flag with a functionality that is so close to the existing functionality, and when you can achieve what you want with very little extra effort on your behalf.

@lexinator
Copy link
Author

ok. thanks for your reply.

@lock lock bot locked as resolved and limited conversation to collaborators May 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

3 participants