mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-11-12 21:12:44 -05:00
fix: Clear connection before cancel
This commit is contained in:
@ -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();
|
||||
|
||||
Reference in New Issue
Block a user