From 582fb101cf86ce2ab05136ce0099aa6c4af0728d Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 2 Feb 2024 10:31:11 -0500 Subject: [PATCH] Minor network fixes --- src/core/network.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/network.cpp b/src/core/network.cpp index 3f2d3cb2..901d291f 100644 --- a/src/core/network.cpp +++ b/src/core/network.cpp @@ -72,7 +72,11 @@ void NetworkAccessManager::processReply(QNetworkReply * reply, NetworkReplyData if (!reply || !reply->isFinished()) return; - auto url = reply->url(); + // The url in the request and the url ultimately processed (reply->url()) may differ if the request was redirected. + // For identification purposes (e.g. knowing if we are rate limited before a request is made) we use the url that + // was originally given for the request. + auto url = data->m_url; + reply->deleteLater(); int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); @@ -88,7 +92,11 @@ void NetworkAccessManager::processReply(QNetworkReply * reply, NetworkReplyData if (statusCode == 304) { // "Not Modified", data hasn't changed since our last request. - data->m_body = this->cache.value(url)->data; + auto cacheEntry = this->cache.value(url, nullptr); + if (cacheEntry) + data->m_body = cacheEntry->data; + else + data->m_error = "Failed to read webpage from cache."; return; }