diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-06-09 14:20:22 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-06-09 14:20:22 +0200 |
commit | 29e0748847dfeabbfaabbec8a588088fd1887fb1 (patch) | |
tree | 734cad813b3fcf383fbaf1dacdb9b8f6420ab9ec /src | |
parent | 447ea52b0750785ba8d3b9fc9845d6f8f4c26811 (diff) |
Show HTTP status message
For example:
warning: unable to download 'https://api.github.com/repos/edolstra/dwarffs/commits/master': HTTP error 403 ('rate limit exceeded'); using cached version
Diffstat (limited to 'src')
-rw-r--r-- | src/libstore/filetransfer.cc | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index 29edbd0ad..99316327b 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -56,6 +56,7 @@ struct curlFileTransfer : public FileTransfer Callback<FileTransferResult> callback; CURL * req = 0; bool active = false; // whether the handle has been added to the multi object + std::string statusMsg; unsigned int attempt = 0; @@ -163,11 +164,13 @@ struct curlFileTransfer : public FileTransfer size_t realSize = size * nmemb; std::string line((char *) contents, realSize); printMsg(lvlVomit, format("got header for '%s': %s") % request.uri % trim(line)); - if (line.compare(0, 5, "HTTP/") == 0) { // new response starts + static std::regex statusLine("HTTP/[^ ]+ +[0-9]+(.*)", std::regex::extended | std::regex::icase); + std::smatch match; + if (std::regex_match(line, match, statusLine)) { result.etag = ""; - auto ss = tokenizeString<vector<string>>(line, " "); result.data = std::make_shared<std::string>(); result.bodySize = 0; + statusMsg = trim(match[1]); acceptRanges = false; encoding = ""; } else { @@ -404,8 +407,8 @@ struct curlFileTransfer : public FileTransfer ? FileTransferError(Interrupted, fmt("%s of '%s' was interrupted", request.verb(), request.uri)) : httpStatus != 0 ? FileTransferError(err, - fmt("unable to %s '%s': HTTP error %d", - request.verb(), request.uri, httpStatus) + fmt("unable to %s '%s': HTTP error %d ('%s')", + request.verb(), request.uri, httpStatus, statusMsg) + (code == CURLE_OK ? "" : fmt(" (curl error: %s)", curl_easy_strerror(code))) ) : FileTransferError(err, |