forked from lix-project/lix
filetransfer: drop errorSink
just accumulate error data into result.data as we would for successful
transfers without a dataCallback. errorSink and data would contain the
same data in error cases anyway, so splitting them is not very useful.
Change-Id: I00e449866454389ac6a564ab411c903fd357dabf
This commit is contained in:
parent
5e69f8aa3d
commit
5420b3afd6
|
@ -90,19 +90,12 @@ struct curlFileTransfer : public FileTransfer
|
||||||
{request.uri}, request.parentAct)
|
{request.uri}, request.parentAct)
|
||||||
, callback(std::move(callback))
|
, callback(std::move(callback))
|
||||||
, finalSink([this](std::string_view data) {
|
, finalSink([this](std::string_view data) {
|
||||||
if (errorSink) {
|
|
||||||
(*errorSink)(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->request.dataCallback) {
|
|
||||||
auto httpStatus = getHTTPStatus();
|
auto httpStatus = getHTTPStatus();
|
||||||
|
|
||||||
/* Only write data to the sink if this is a
|
/* Only write data to the sink if this is a
|
||||||
successful response. */
|
successful response. */
|
||||||
if (successfulStatuses.count(httpStatus)) {
|
if (successfulStatuses.count(httpStatus) && this->request.dataCallback) {
|
||||||
writtenToSink += data.size();
|
writtenToSink += data.size();
|
||||||
this->request.dataCallback(data);
|
this->request.dataCallback(data);
|
||||||
}
|
|
||||||
} else
|
} else
|
||||||
this->result.data.append(data);
|
this->result.data.append(data);
|
||||||
})
|
})
|
||||||
|
@ -148,7 +141,6 @@ struct curlFileTransfer : public FileTransfer
|
||||||
|
|
||||||
LambdaSink finalSink;
|
LambdaSink finalSink;
|
||||||
std::shared_ptr<FinishSink> decompressionSink;
|
std::shared_ptr<FinishSink> decompressionSink;
|
||||||
std::optional<StringSink> errorSink;
|
|
||||||
|
|
||||||
std::exception_ptr writeException;
|
std::exception_ptr writeException;
|
||||||
|
|
||||||
|
@ -184,13 +176,6 @@ struct curlFileTransfer : public FileTransfer
|
||||||
|
|
||||||
if (!decompressionSink) {
|
if (!decompressionSink) {
|
||||||
decompressionSink = makeDecompressionSink(encoding, finalSink);
|
decompressionSink = makeDecompressionSink(encoding, finalSink);
|
||||||
if (! successfulStatuses.count(getHTTPStatus())) {
|
|
||||||
// In this case we want to construct a TeeSink, to keep
|
|
||||||
// the response around (which we figure won't be big
|
|
||||||
// like an actual download should be) to improve error
|
|
||||||
// messages.
|
|
||||||
errorSink = StringSink { };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(*decompressionSink)({(char *) contents, realSize});
|
(*decompressionSink)({(char *) contents, realSize});
|
||||||
|
@ -448,8 +433,8 @@ struct curlFileTransfer : public FileTransfer
|
||||||
attempt++;
|
attempt++;
|
||||||
|
|
||||||
std::optional<std::string> response;
|
std::optional<std::string> response;
|
||||||
if (errorSink)
|
if (!successfulStatuses.count(httpStatus))
|
||||||
response = std::move(errorSink->s);
|
response = std::move(result.data);
|
||||||
auto exc =
|
auto exc =
|
||||||
code == CURLE_ABORTED_BY_CALLBACK && _isInterrupted
|
code == CURLE_ABORTED_BY_CALLBACK && _isInterrupted
|
||||||
? FileTransferError(Interrupted, std::move(response), "%s of '%s' was interrupted", request.verb(), request.uri)
|
? FileTransferError(Interrupted, std::move(response), "%s of '%s' was interrupted", request.verb(), request.uri)
|
||||||
|
|
Loading…
Reference in a new issue