From cbf7c09bf4287c517bf736d73b55d0137c3492a5 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 8 Dec 2024 16:33:35 +0800 Subject: [PATCH] Use built-in method for setting header PR #21961. --- src/base/net/downloadmanager.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/base/net/downloadmanager.cpp b/src/base/net/downloadmanager.cpp index b84006f6f..2d75de73c 100644 --- a/src/base/net/downloadmanager.cpp +++ b/src/base/net/downloadmanager.cpp @@ -320,14 +320,11 @@ void Net::DownloadManager::processRequest(DownloadHandlerImpl *downloadHandler) const DownloadRequest downloadRequest = downloadHandler->downloadRequest(); QNetworkRequest request {downloadRequest.url()}; - - if (downloadRequest.userAgent().isEmpty()) - request.setRawHeader("User-Agent", getBrowserUserAgent()); - else - request.setRawHeader("User-Agent", downloadRequest.userAgent().toUtf8()); + request.setHeader(QNetworkRequest::UserAgentHeader, (downloadRequest.userAgent().isEmpty() + ? getBrowserUserAgent() : downloadRequest.userAgent().toUtf8())); // Spoof HTTP Referer to allow adding torrent link from Torcache/KickAssTorrents - request.setRawHeader("Referer", request.url().toEncoded().data()); + request.setRawHeader("Referer", request.url().toEncoded()); #ifdef QT_NO_COMPRESS // The macro "QT_NO_COMPRESS" defined in QT will disable the zlib related features // and reply data auto-decompression in QT will also be disabled. But we can support