diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2023-01-20 14:44:54 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2023-01-23 14:38:11 +0300 |
commit | 59a86f5ea854475b365679bd8d7604e50b724783 (patch) | |
tree | c04573b6b75783c1751c3e45e81e7ee596c04e59 /bpkg/fetch.cxx | |
parent | 8085f0f8ae4520fcd9ac9bf1ec9ac7ec5f1aad90 (diff) |
Fix unexpected 'unable to read HTTP response status line' fetch error
Diffstat (limited to 'bpkg/fetch.cxx')
-rw-r--r-- | bpkg/fetch.cxx | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/bpkg/fetch.cxx b/bpkg/fetch.cxx index 573dfde..a9e4df2 100644 --- a/bpkg/fetch.cxx +++ b/bpkg/fetch.cxx @@ -317,7 +317,6 @@ namespace bpkg cstrings args { prog.string ().c_str (), - "-f", // Fail on HTTP errors (e.g., 404). "-L", // Follow redirects. "-A", ua.c_str () }; @@ -397,12 +396,24 @@ namespace bpkg // Status code. // + // Add the --include|-i option if HTTP status code needs to be retrieved + // in order to include the HTTP response headers to the output. Otherwise, + // add the --fail|-f option not to print the response body and exit with + // non-zero status code on HTTP error (e.g., 404), so that the caller can + // recognize the request failure. + // + // Note that older versions of curl (e.g., 7.55.1) ignore the --include|-i + // option in the presence of the --fail|-f option on HTTP errors and don't + // print the response status line and headers. + // if (out_is != nullptr) { assert (!fo); // Currently unsupported (see start_fetch() for details). args.push_back ("-i"); } + else + args.push_back ("-f"); args.push_back (url.c_str ()); args.push_back (nullptr); @@ -482,8 +493,8 @@ namespace bpkg assert (e != nullptr); return *e == '\0' && c >= 100 && c < 600 - ? static_cast<uint16_t> (c) - : 0; + ? static_cast<uint16_t> (c) + : 0; }; // Read the CRLF-terminated line from the stream stripping the trailing @@ -535,10 +546,7 @@ namespace bpkg close_streams (); fail << "invalid HTTP response status line '" << l - << "' while fetching " << url; - - assert (false); // Can't be here. - return 0; + << "' while fetching " << url << endf; }; sc = read_status (); |