fix: Clear connection before cancel

This commit is contained in:
Petr Mironychev
2025-11-01 20:51:01 +01:00
parent 1848d44503
commit e7110810f8
4 changed files with 50 additions and 5 deletions

View File

@ -60,18 +60,23 @@ void HttpClient::onSendRequest(const HttpRequest &request)
void HttpClient::onReadyRead()
{
QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
if (!reply)
if (!reply || reply->isFinished())
return;
QString requestId;
{
QMutexLocker locker(&m_mutex);
bool found = false;
for (auto it = m_activeRequests.begin(); it != m_activeRequests.end(); ++it) {
if (it.value() == reply) {
requestId = it.key();
found = true;
break;
}
}
if (!found)
return;
}
if (requestId.isEmpty())
@ -89,19 +94,28 @@ void HttpClient::onFinished()
if (!reply)
return;
reply->disconnect();
QString requestId;
bool hasError = false;
QString errorMsg;
{
QMutexLocker locker(&m_mutex);
bool found = false;
for (auto it = m_activeRequests.begin(); it != m_activeRequests.end(); ++it) {
if (it.value() == reply) {
requestId = it.key();
m_activeRequests.erase(it);
found = true;
break;
}
}
if (!found) {
reply->deleteLater();
return;
}
if (reply->error() != QNetworkReply::NoError) {
hasError = true;
errorMsg = reply->errorString();