kioslave: try authorizing from cache first in curl slave

so that it does not look like a brute-force attack to servers (multiple
jobs are started for thumbnails and such), less round-trips too

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-05-05 05:43:08 +03:00
parent dfc39666d2
commit 972b231e4a

View file

@ -1053,34 +1053,31 @@ bool CurlProtocol::setupCurl(const KUrl &url, const bool ftp)
// password part // password part
CURLcode CurlProtocol::performCurl(const KUrl &url, KUrl *redirecturl) CURLcode CurlProtocol::performCurl(const KUrl &url, KUrl *redirecturl)
{ {
CURLcode curlresult = curl_easy_perform(m_curl); CURLcode curlresult = CURLE_OK;
const QString urlusername = url.userName();
KIO::AuthInfo kioauthinfo; KIO::AuthInfo kioauthinfo;
kioauthinfo.url = url; kioauthinfo.url = url;
kioauthinfo.username = urlusername; kioauthinfo.username = url.userName();
kioauthinfo.password = url.password(); kioauthinfo.password = url.password();
if (curlresult != CURLE_OK) { if (checkCachedAuthentication(kioauthinfo)) {
KIO::Error kioerror = curlToKIOError(curlresult, m_curl); kDebug(7103) << "Authorizing from cache" << url.prettyUrl();
if (kioerror == KIO::ERR_COULD_NOT_LOGIN) { curlresult = setupAuth(kioauthinfo.username, kioauthinfo.password);
kDebug(7103) << "Authorizing from cache" << url.prettyUrl(); if (curlresult != CURLE_OK) {
if (checkCachedAuthentication(kioauthinfo)) { return curlresult;
curlresult = setupAuth(kioauthinfo.username, kioauthinfo.password); }
if (curlresult != CURLE_OK) { curlresult = curl_easy_perform(m_curl);
return curlresult; if (curlresult != CURLE_OK) {
} KIO::Error kioerror = curlToKIOError(curlresult, m_curl);
curlresult = curl_easy_perform(m_curl); if (kioerror != KIO::ERR_COULD_NOT_LOGIN) {
if (curlresult != CURLE_OK) { kDebug(7103) << "Going to redirect for cached authorization";
kioerror = curlToKIOError(curlresult, m_curl); KUrl newurl(url);
if (kioerror != KIO::ERR_COULD_NOT_LOGIN) { newurl.setUserName(kioauthinfo.username);
kDebug(7103) << "Going to redirect for cache authorization"; newurl.setPassword(kioauthinfo.password);
KUrl newurl(url); *redirecturl = newurl;
newurl.setUserName(kioauthinfo.username);
newurl.setPassword(kioauthinfo.password);
*redirecturl = newurl;
}
}
} }
} }
} else {
kDebug(7103) << "No cached authorization" << url.prettyUrl();
curlresult = curl_easy_perform(m_curl);
} }
if (curlresult != CURLE_OK) { if (curlresult != CURLE_OK) {