forked from lix-project/lix
parent
a8d51767ee
commit
72e17290d4
|
@ -72,6 +72,17 @@ struct curlFileTransfer : public FileTransfer
|
||||||
|
|
||||||
curl_off_t writtenToSink = 0;
|
curl_off_t writtenToSink = 0;
|
||||||
|
|
||||||
|
/* Get the HTTP status code, or 0 for other protocols. */
|
||||||
|
long getHTTPStatus()
|
||||||
|
{
|
||||||
|
long httpStatus = 0;
|
||||||
|
long protocol = 0;
|
||||||
|
curl_easy_getinfo(req, CURLINFO_PROTOCOL, &protocol);
|
||||||
|
if (protocol == CURLPROTO_HTTP || protocol == CURLPROTO_HTTPS)
|
||||||
|
curl_easy_getinfo(req, CURLINFO_RESPONSE_CODE, &httpStatus);
|
||||||
|
return httpStatus;
|
||||||
|
}
|
||||||
|
|
||||||
TransferItem(curlFileTransfer & fileTransfer,
|
TransferItem(curlFileTransfer & fileTransfer,
|
||||||
const FileTransferRequest & request,
|
const FileTransferRequest & request,
|
||||||
Callback<FileTransferResult> && callback)
|
Callback<FileTransferResult> && callback)
|
||||||
|
@ -83,8 +94,7 @@ struct curlFileTransfer : public FileTransfer
|
||||||
, callback(std::move(callback))
|
, callback(std::move(callback))
|
||||||
, finalSink([this](const unsigned char * data, size_t len) {
|
, finalSink([this](const unsigned char * data, size_t len) {
|
||||||
if (this->request.dataCallback) {
|
if (this->request.dataCallback) {
|
||||||
long httpStatus = 0;
|
auto httpStatus = getHTTPStatus();
|
||||||
curl_easy_getinfo(req, CURLINFO_RESPONSE_CODE, &httpStatus);
|
|
||||||
|
|
||||||
/* Only write data to the sink if this is a
|
/* Only write data to the sink if this is a
|
||||||
successful response. */
|
successful response. */
|
||||||
|
@ -316,8 +326,7 @@ struct curlFileTransfer : public FileTransfer
|
||||||
|
|
||||||
void finish(CURLcode code)
|
void finish(CURLcode code)
|
||||||
{
|
{
|
||||||
long httpStatus = 0;
|
auto httpStatus = getHTTPStatus();
|
||||||
curl_easy_getinfo(req, CURLINFO_RESPONSE_CODE, &httpStatus);
|
|
||||||
|
|
||||||
char * effectiveUriCStr;
|
char * effectiveUriCStr;
|
||||||
curl_easy_getinfo(req, CURLINFO_EFFECTIVE_URL, &effectiveUriCStr);
|
curl_easy_getinfo(req, CURLINFO_EFFECTIVE_URL, &effectiveUriCStr);
|
||||||
|
@ -344,7 +353,7 @@ struct curlFileTransfer : public FileTransfer
|
||||||
failEx(writeException);
|
failEx(writeException);
|
||||||
|
|
||||||
else if (code == CURLE_OK &&
|
else if (code == CURLE_OK &&
|
||||||
(httpStatus == 200 || httpStatus == 201 || httpStatus == 204 || httpStatus == 206 || httpStatus == 304 || httpStatus == 226 /* FTP */ || httpStatus == 0 /* other protocol */))
|
(httpStatus == 200 || httpStatus == 201 || httpStatus == 204 || httpStatus == 206 || httpStatus == 304 || httpStatus == 0 /* other protocol */))
|
||||||
{
|
{
|
||||||
result.cached = httpStatus == 304;
|
result.cached = httpStatus == 304;
|
||||||
act.progress(result.bodySize, result.bodySize);
|
act.progress(result.bodySize, result.bodySize);
|
||||||
|
|
Loading…
Reference in a new issue