Yes, this is related to Getting curl to output HTTP status code? but unfortunately not the same.
In a script I would like to run:
curl -qSfsw %{http_code} URL
where the -f
option ensures that the exit code is non-zero to signal an error. On success I want to get the (textual) output from the fetched file, whereas otherwise I want to use the error code.
Problem:
- Due to race conditions I must not use more than a single HTTP request
- I cannot use a temporary file for storage of the content
How can I still split the HTTP return code from the actual output?
Pseudo code:
fetch URL
if http-error then
print http-error-code
else
print http-body # <- but without the HTTP status code
endif