Changeset View
Changeset View
Standalone View
Standalone View
src/ioslaves/http/http.cpp
Show First 20 Lines • Show All 437 Lines • ▼ Show 20 Line(s) | |||||
438 | { | 438 | { | ||
439 | // Follow HTTP/1.1 spec and enable keep-alive by default | 439 | // Follow HTTP/1.1 spec and enable keep-alive by default | ||
440 | // unless the remote side tells us otherwise or we determine | 440 | // unless the remote side tells us otherwise or we determine | ||
441 | // the persistent link has been terminated by the remote end. | 441 | // the persistent link has been terminated by the remote end. | ||
442 | m_request.isKeepAlive = true; | 442 | m_request.isKeepAlive = true; | ||
443 | m_request.keepAliveTimeout = 0; | 443 | m_request.keepAliveTimeout = 0; | ||
444 | 444 | | |||
445 | m_request.redirectUrl = QUrl(); | 445 | m_request.redirectUrl = QUrl(); | ||
446 | m_request.useCookieJar = config()->readEntry("Cookies", false); | 446 | m_request.useCookieJar = mapConfig().value(QStringLiteral("Cookies"), false).toBool(); | ||
447 | m_request.cacheTag.useCache = config()->readEntry("UseCache", true); | 447 | m_request.cacheTag.useCache = mapConfig().value(QStringLiteral("UseCache"), true).toBool(); | ||
448 | m_request.preferErrorPage = config()->readEntry("errorPage", true); | 448 | m_request.preferErrorPage = mapConfig().value(QStringLiteral("errorPage"), true).toBool(); | ||
449 | const bool noAuth = config()->readEntry("no-auth", false); | 449 | const bool noAuth = mapConfig().value(QStringLiteral("no-auth"), false).toBool(); | ||
450 | m_request.doNotWWWAuthenticate = config()->readEntry("no-www-auth", noAuth); | 450 | m_request.doNotWWWAuthenticate = mapConfig().value(QStringLiteral("no-www-auth"), noAuth).toBool(); | ||
451 | m_request.doNotProxyAuthenticate = config()->readEntry("no-proxy-auth", noAuth); | 451 | m_request.doNotProxyAuthenticate = mapConfig().value(QStringLiteral("no-proxy-auth"), noAuth).toBool(); | ||
452 | m_strCacheDir = config()->readPathEntry("CacheDir", QString()); | 452 | m_strCacheDir = config()->readPathEntry(QStringLiteral("CacheDir"), QString()); | ||
453 | m_maxCacheAge = config()->readEntry("MaxCacheAge", DEFAULT_MAX_CACHE_AGE); | 453 | m_maxCacheAge = mapConfig().value(QStringLiteral("MaxCacheAge"), DEFAULT_MAX_CACHE_AGE).toInt(); | ||
454 | m_request.windowId = config()->readEntry("window-id"); | 454 | m_request.windowId = mapConfig().value(QStringLiteral("window-id")).toString(); | ||
455 | 455 | | |||
456 | m_request.methodStringOverride = metaData(QStringLiteral("CustomHTTPMethod")); | 456 | m_request.methodStringOverride = metaData(QStringLiteral("CustomHTTPMethod")); | ||
457 | m_request.sentMethodString.clear(); | 457 | m_request.sentMethodString.clear(); | ||
458 | 458 | | |||
459 | qCDebug(KIO_HTTP) << "Window Id =" << m_request.windowId; | 459 | qCDebug(KIO_HTTP) << "Window Id =" << m_request.windowId; | ||
460 | qCDebug(KIO_HTTP) << "ssl_was_in_use =" << metaData(QStringLiteral("ssl_was_in_use")); | 460 | qCDebug(KIO_HTTP) << "ssl_was_in_use =" << metaData(QStringLiteral("ssl_was_in_use")); | ||
461 | 461 | | |||
462 | m_request.referrer.clear(); | 462 | m_request.referrer.clear(); | ||
463 | // RFC 2616: do not send the referrer if the referrer page was served using SSL and | 463 | // RFC 2616: do not send the referrer if the referrer page was served using SSL and | ||
464 | // the current page does not use SSL. | 464 | // the current page does not use SSL. | ||
465 | if (config()->readEntry("SendReferrer", true) && | 465 | if (mapConfig().value(QStringLiteral("SendReferrer"), true).toBool() && | ||
466 | (isEncryptedHttpVariety(m_protocol) || metaData(QStringLiteral("ssl_was_in_use")) != QLatin1String("TRUE"))) { | 466 | (isEncryptedHttpVariety(m_protocol) || metaData(QStringLiteral("ssl_was_in_use")) != QLatin1String("TRUE"))) { | ||
467 | QUrl refUrl(metaData(QStringLiteral("referrer"))); | 467 | QUrl refUrl(metaData(QStringLiteral("referrer"))); | ||
468 | if (refUrl.isValid()) { | 468 | if (refUrl.isValid()) { | ||
469 | // Sanitize | 469 | // Sanitize | ||
470 | QString protocol = refUrl.scheme(); | 470 | QString protocol = refUrl.scheme(); | ||
471 | if (protocol.startsWith(QLatin1String("webdav"))) { | 471 | if (protocol.startsWith(QLatin1String("webdav"))) { | ||
472 | protocol.replace(0, 6, QStringLiteral("http")); | 472 | protocol.replace(0, 6, QStringLiteral("http")); | ||
473 | refUrl.setScheme(protocol); | 473 | refUrl.setScheme(protocol); | ||
474 | } | 474 | } | ||
475 | 475 | | |||
476 | if (protocol.startsWith(QLatin1String("http"))) { | 476 | if (protocol.startsWith(QLatin1String("http"))) { | ||
477 | m_request.referrer = toQString(refUrl.toEncoded(QUrl::RemoveUserInfo | QUrl::RemoveFragment)); | 477 | m_request.referrer = toQString(refUrl.toEncoded(QUrl::RemoveUserInfo | QUrl::RemoveFragment)); | ||
478 | } | 478 | } | ||
479 | } | 479 | } | ||
480 | } | 480 | } | ||
481 | 481 | | |||
482 | if (config()->readEntry("SendLanguageSettings", true)) { | 482 | if (mapConfig().value(QStringLiteral("SendLanguageSettings"), true).toBool()) { | ||
483 | m_request.charsets = config()->readEntry("Charsets", DEFAULT_PARTIAL_CHARSET_HEADER); | 483 | m_request.charsets = mapConfig().value(QStringLiteral("Charsets"), QStringLiteral(DEFAULT_PARTIAL_CHARSET_HEADER)).toString(); | ||
484 | if (!m_request.charsets.contains(QLatin1String("*;"), Qt::CaseInsensitive)) { | 484 | if (!m_request.charsets.contains(QLatin1String("*;"), Qt::CaseInsensitive)) { | ||
485 | m_request.charsets += QLatin1String(",*;q=0.5"); | 485 | m_request.charsets += QLatin1String(",*;q=0.5"); | ||
486 | } | 486 | } | ||
487 | m_request.languages = config()->readEntry("Languages", DEFAULT_LANGUAGE_HEADER); | 487 | m_request.languages = mapConfig().value(QStringLiteral("Languages"), QStringLiteral(DEFAULT_LANGUAGE_HEADER)).toString(); | ||
488 | } else { | 488 | } else { | ||
489 | m_request.charsets.clear(); | 489 | m_request.charsets.clear(); | ||
490 | m_request.languages.clear(); | 490 | m_request.languages.clear(); | ||
491 | } | 491 | } | ||
492 | 492 | | |||
493 | // Adjust the offset value based on the "range-start" meta-data. | 493 | // Adjust the offset value based on the "range-start" meta-data. | ||
494 | QString resumeOffset = metaData(QStringLiteral("range-start")); | 494 | QString resumeOffset = metaData(QStringLiteral("range-start")); | ||
495 | if (resumeOffset.isEmpty()) { | 495 | if (resumeOffset.isEmpty()) { | ||
Show All 10 Lines | 505 | if (resumeEndOffset.isEmpty()) { | |||
506 | resumeEndOffset = metaData(QStringLiteral("resume_until")); // old name | 506 | resumeEndOffset = metaData(QStringLiteral("resume_until")); // old name | ||
507 | } | 507 | } | ||
508 | if (!resumeEndOffset.isEmpty()) { | 508 | if (!resumeEndOffset.isEmpty()) { | ||
509 | m_request.endoffset = resumeEndOffset.toULongLong(); | 509 | m_request.endoffset = resumeEndOffset.toULongLong(); | ||
510 | } else { | 510 | } else { | ||
511 | m_request.endoffset = 0; | 511 | m_request.endoffset = 0; | ||
512 | } | 512 | } | ||
513 | 513 | | |||
514 | m_request.disablePassDialog = config()->readEntry("DisablePassDlg", false); | 514 | m_request.disablePassDialog = mapConfig().value(QStringLiteral("DisablePassDlg"), false).toBool(); | ||
515 | m_request.allowTransferCompression = config()->readEntry("AllowCompressedPage", true); | 515 | m_request.allowTransferCompression = mapConfig().value(QStringLiteral("AllowCompressedPage"), true).toBool(); | ||
516 | m_request.id = metaData(QStringLiteral("request-id")); | 516 | m_request.id = metaData(QStringLiteral("request-id")); | ||
517 | 517 | | |||
518 | // Store user agent for this host. | 518 | // Store user agent for this host. | ||
519 | if (config()->readEntry("SendUserAgent", true)) { | 519 | if (mapConfig().value(QStringLiteral("SendUserAgent"), true).toBool()) { | ||
520 | m_request.userAgent = metaData(QStringLiteral("UserAgent")); | 520 | m_request.userAgent = metaData(QStringLiteral("UserAgent")); | ||
521 | } else { | 521 | } else { | ||
522 | m_request.userAgent.clear(); | 522 | m_request.userAgent.clear(); | ||
523 | } | 523 | } | ||
524 | 524 | | |||
525 | m_request.cacheTag.etag.clear(); | 525 | m_request.cacheTag.etag.clear(); | ||
526 | m_request.cacheTag.servedDate = QDateTime(); | 526 | m_request.cacheTag.servedDate = QDateTime(); | ||
527 | m_request.cacheTag.lastModifiedDate = QDateTime(); | 527 | m_request.cacheTag.lastModifiedDate = QDateTime(); | ||
▲ Show 20 Lines • Show All 1627 Lines • ▼ Show 20 Line(s) | 2147 | { | |||
2155 | 2155 | | |||
2156 | clearUnreadBuffer(); | 2156 | clearUnreadBuffer(); | ||
2157 | 2157 | | |||
2158 | int connectError = 0; | 2158 | int connectError = 0; | ||
2159 | QString errorString; | 2159 | QString errorString; | ||
2160 | 2160 | | |||
2161 | // Get proxy information... | 2161 | // Get proxy information... | ||
2162 | if (m_request.proxyUrls.isEmpty()) { | 2162 | if (m_request.proxyUrls.isEmpty()) { | ||
2163 | m_request.proxyUrls = config()->readEntry("ProxyUrls", QStringList()); | 2163 | m_request.proxyUrls = mapConfig().value(QStringLiteral("ProxyUrls"), QStringList()).toStringList(); | ||
2164 | qCDebug(KIO_HTTP) << "Proxy URLs:" << m_request.proxyUrls; | 2164 | qCDebug(KIO_HTTP) << "Proxy URLs:" << m_request.proxyUrls; | ||
2165 | } | 2165 | } | ||
2166 | 2166 | | |||
2167 | if (m_request.proxyUrls.isEmpty()) { | 2167 | if (m_request.proxyUrls.isEmpty()) { | ||
2168 | QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy); | 2168 | QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy); | ||
2169 | connectError = connectToHost(m_request.url.host(), m_request.url.port(defaultPort()), &errorString); | 2169 | connectError = connectToHost(m_request.url.host(), m_request.url.port(defaultPort()), &errorString); | ||
2170 | } else { | 2170 | } else { | ||
2171 | QList<QUrl> badProxyUrls; | 2171 | QList<QUrl> badProxyUrls; | ||
▲ Show 20 Lines • Show All 405 Lines • ▼ Show 20 Line(s) | 2379 | { | |||
2577 | if (!contentType.isEmpty()) { | 2577 | if (!contentType.isEmpty()) { | ||
2578 | if (!contentType.startsWith(QLatin1String("content-type"), Qt::CaseInsensitive)) { | 2578 | if (!contentType.startsWith(QLatin1String("content-type"), Qt::CaseInsensitive)) { | ||
2579 | header += QLatin1String("Content-Type: "); | 2579 | header += QLatin1String("Content-Type: "); | ||
2580 | } | 2580 | } | ||
2581 | header += contentType + QLatin1String("\r\n"); | 2581 | header += contentType + QLatin1String("\r\n"); | ||
2582 | } | 2582 | } | ||
2583 | 2583 | | |||
2584 | // DoNotTrack feature... | 2584 | // DoNotTrack feature... | ||
2585 | if (config()->readEntry("DoNotTrack", false)) { | 2585 | if (mapConfig().value(QStringLiteral("DoNotTrack"), false).toBool()) { | ||
2586 | header += QLatin1String("DNT: 1\r\n"); | 2586 | header += QLatin1String("DNT: 1\r\n"); | ||
2587 | } | 2587 | } | ||
2588 | 2588 | | |||
2589 | // Remember that at least one failed (with 401 or 407) request/response | 2589 | // Remember that at least one failed (with 401 or 407) request/response | ||
2590 | // roundtrip is necessary for the server to tell us that it requires | 2590 | // roundtrip is necessary for the server to tell us that it requires | ||
2591 | // authentication. However, we proactively add authentication headers if when | 2591 | // authentication. However, we proactively add authentication headers if when | ||
2592 | // we have cached credentials to avoid the extra roundtrip where possible. | 2592 | // we have cached credentials to avoid the extra roundtrip where possible. | ||
2593 | header += authenticationHeader(); | 2593 | header += authenticationHeader(); | ||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Line(s) | |||||
2657 | infoMessage(i18n("%1 contacted. Waiting for reply...", m_request.url.host())); | 2657 | infoMessage(i18n("%1 contacted. Waiting for reply...", m_request.url.host())); | ||
2658 | 2658 | | |||
2659 | return res; | 2659 | return res; | ||
2660 | } | 2660 | } | ||
2661 | 2661 | | |||
2662 | void HTTPProtocol::forwardHttpResponseHeader(bool forwardImmediately) | 2662 | void HTTPProtocol::forwardHttpResponseHeader(bool forwardImmediately) | ||
2663 | { | 2663 | { | ||
2664 | // Send the response header if it was requested... | 2664 | // Send the response header if it was requested... | ||
2665 | if (!config()->readEntry("PropagateHttpHeader", false)) { | 2665 | if (!mapConfig().value(QStringLiteral("PropagateHttpHeader"), false).toBool()) { | ||
2666 | return; | 2666 | return; | ||
2667 | } | 2667 | } | ||
2668 | 2668 | | |||
2669 | setMetaData(QStringLiteral("HTTP-Headers"), m_responseHeaders.join(QLatin1Char('\n'))); | 2669 | setMetaData(QStringLiteral("HTTP-Headers"), m_responseHeaders.join(QLatin1Char('\n'))); | ||
2670 | 2670 | | |||
2671 | if (forwardImmediately) { | 2671 | if (forwardImmediately) { | ||
2672 | sendMetaData(); | 2672 | sendMetaData(); | ||
2673 | } | 2673 | } | ||
▲ Show 20 Lines • Show All 712 Lines • ▼ Show 20 Line(s) | 3108 | if (!noHeadersFound) { | |||
3386 | QByteArray cookieStr; // In case we get a cookie. | 3386 | QByteArray cookieStr; // In case we get a cookie. | ||
3387 | tIt = tokenizer.iterator("set-cookie"); | 3387 | tIt = tokenizer.iterator("set-cookie"); | ||
3388 | while (tIt.hasNext()) { | 3388 | while (tIt.hasNext()) { | ||
3389 | cookieStr += "Set-Cookie: " + tIt.next() + '\n'; | 3389 | cookieStr += "Set-Cookie: " + tIt.next() + '\n'; | ||
3390 | } | 3390 | } | ||
3391 | if (!cookieStr.isEmpty()) { | 3391 | if (!cookieStr.isEmpty()) { | ||
3392 | if ((m_request.cookieMode == HTTPRequest::CookiesAuto) && m_request.useCookieJar) { | 3392 | if ((m_request.cookieMode == HTTPRequest::CookiesAuto) && m_request.useCookieJar) { | ||
3393 | // Give cookies to the cookiejar. | 3393 | // Give cookies to the cookiejar. | ||
3394 | const QString domain = config()->readEntry("cross-domain"); | 3394 | const QString domain = mapConfig().value(QStringLiteral("cross-domain")).toString(); | ||
3395 | if (!domain.isEmpty() && isCrossDomainRequest(m_request.url.host(), domain)) { | 3395 | if (!domain.isEmpty() && isCrossDomainRequest(m_request.url.host(), domain)) { | ||
3396 | cookieStr = "Cross-Domain\n" + cookieStr; | 3396 | cookieStr = "Cross-Domain\n" + cookieStr; | ||
3397 | } | 3397 | } | ||
3398 | addCookies(m_request.url.toString(), cookieStr); | 3398 | addCookies(m_request.url.toString(), cookieStr); | ||
3399 | } else if (m_request.cookieMode == HTTPRequest::CookiesManual) { | 3399 | } else if (m_request.cookieMode == HTTPRequest::CookiesManual) { | ||
3400 | // Pass cookie to application | 3400 | // Pass cookie to application | ||
3401 | setMetaData(QStringLiteral("setcookies"), QString::fromUtf8(cookieStr)); // ## is encoding ok? | 3401 | setMetaData(QStringLiteral("setcookies"), QString::fromUtf8(cookieStr)); // ## is encoding ok? | ||
3402 | } | 3402 | } | ||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Line(s) | 3505 | if (m_request.cacheTag.policy == CC_Verify && | |||
3506 | m_request.cacheTag.plan(m_maxCacheAge) != CacheTag::UseCached) { | 3506 | m_request.cacheTag.plan(m_maxCacheAge) != CacheTag::UseCached) { | ||
3507 | qCDebug(KIO_HTTP) << "Reading resource from cache even though the cache plan is not " | 3507 | qCDebug(KIO_HTTP) << "Reading resource from cache even though the cache plan is not " | ||
3508 | "UseCached; the server is probably sending wrong expiry information."; | 3508 | "UseCached; the server is probably sending wrong expiry information."; | ||
3509 | } | 3509 | } | ||
3510 | // parseHeaderFromCache replaces this method in case of cached content | 3510 | // parseHeaderFromCache replaces this method in case of cached content | ||
3511 | return parseHeaderFromCache(); | 3511 | return parseHeaderFromCache(); | ||
3512 | } | 3512 | } | ||
3513 | 3513 | | |||
3514 | if (config()->readEntry("PropagateHttpHeader", false) || | 3514 | if (mapConfig().value(QStringLiteral("PropagateHttpHeader"), false).toBool() || | ||
3515 | m_request.cacheTag.ioMode == WriteToCache) { | 3515 | m_request.cacheTag.ioMode == WriteToCache) { | ||
3516 | // store header lines if they will be used; note that the tokenizer removing | 3516 | // store header lines if they will be used; note that the tokenizer removing | ||
3517 | // line continuation special cases is probably more good than bad. | 3517 | // line continuation special cases is probably more good than bad. | ||
3518 | int nextLinePos = 0; | 3518 | int nextLinePos = 0; | ||
3519 | int prevLinePos = 0; | 3519 | int prevLinePos = 0; | ||
3520 | bool haveMore = true; | 3520 | bool haveMore = true; | ||
3521 | while (haveMore) { | 3521 | while (haveMore) { | ||
3522 | haveMore = nextLine(buffer, &nextLinePos, bufPos); | 3522 | haveMore = nextLine(buffer, &nextLinePos, bufPos); | ||
▲ Show 20 Lines • Show All 243 Lines • ▼ Show 20 Line(s) | 3600 | { | |||
3766 | if (mayCache && m_request.responseCode == 200 && !m_mimeType.isEmpty()) { | 3766 | if (mayCache && m_request.responseCode == 200 && !m_mimeType.isEmpty()) { | ||
3767 | qCDebug(KIO_HTTP) << "Cache, adding" << m_request.url; | 3767 | qCDebug(KIO_HTTP) << "Cache, adding" << m_request.url; | ||
3768 | // ioMode can still be ReadFromCache here if we're performing a conditional get | 3768 | // ioMode can still be ReadFromCache here if we're performing a conditional get | ||
3769 | // aka validation | 3769 | // aka validation | ||
3770 | m_request.cacheTag.ioMode = WriteToCache; | 3770 | m_request.cacheTag.ioMode = WriteToCache; | ||
3771 | if (!cacheFileOpenWrite()) { | 3771 | if (!cacheFileOpenWrite()) { | ||
3772 | qCDebug(KIO_HTTP) << "Error creating cache entry for" << m_request.url << "!"; | 3772 | qCDebug(KIO_HTTP) << "Error creating cache entry for" << m_request.url << "!"; | ||
3773 | } | 3773 | } | ||
3774 | m_maxCacheSize = config()->readEntry("MaxCacheSize", DEFAULT_MAX_CACHE_SIZE); | 3774 | m_maxCacheSize = mapConfig().value(QStringLiteral("MaxCacheSize"), DEFAULT_MAX_CACHE_SIZE).toInt(); | ||
3775 | } else if (m_request.responseCode == 304 && m_request.cacheTag.file) { | 3775 | } else if (m_request.responseCode == 304 && m_request.cacheTag.file) { | ||
3776 | if (!mayCache) { | 3776 | if (!mayCache) { | ||
3777 | qCDebug(KIO_HTTP) << "This webserver is confused about the cacheability of the data it sends."; | 3777 | qCDebug(KIO_HTTP) << "This webserver is confused about the cacheability of the data it sends."; | ||
3778 | } | 3778 | } | ||
3779 | // the cache file should still be open for reading, see satisfyRequestFromCache(). | 3779 | // the cache file should still be open for reading, see satisfyRequestFromCache(). | ||
3780 | Q_ASSERT(m_request.cacheTag.file->openMode() == QIODevice::ReadOnly); | 3780 | Q_ASSERT(m_request.cacheTag.file->openMode() == QIODevice::ReadOnly); | ||
3781 | Q_ASSERT(m_request.cacheTag.ioMode == ReadFromCache); | 3781 | Q_ASSERT(m_request.cacheTag.ioMode == ReadFromCache); | ||
3782 | } else { | 3782 | } else { | ||
▲ Show 20 Lines • Show All 1330 Lines • ▼ Show 20 Line(s) | |||||
5113 | 5113 | | |||
5114 | QString HTTPProtocol::authenticationHeader() | 5114 | QString HTTPProtocol::authenticationHeader() | ||
5115 | { | 5115 | { | ||
5116 | QByteArray ret; | 5116 | QByteArray ret; | ||
5117 | 5117 | | |||
5118 | // If the internal meta-data "cached-www-auth" is set, then check for cached | 5118 | // If the internal meta-data "cached-www-auth" is set, then check for cached | ||
5119 | // authentication data and preemptively send the authentication header if a | 5119 | // authentication data and preemptively send the authentication header if a | ||
5120 | // matching one is found. | 5120 | // matching one is found. | ||
5121 | if (!m_wwwAuth && config()->readEntry("cached-www-auth", false)) { | 5121 | if (!m_wwwAuth && mapConfig().value(QStringLiteral("cached-www-auth"), false).toBool()) { | ||
5122 | KIO::AuthInfo authinfo; | 5122 | KIO::AuthInfo authinfo; | ||
5123 | authinfo.url = m_request.url; | 5123 | authinfo.url = m_request.url; | ||
5124 | authinfo.realmValue = config()->readEntry("www-auth-realm", QString()); | 5124 | authinfo.realmValue = mapConfig().value(QStringLiteral("www-auth-realm"), QString()).toString(); | ||
5125 | // If no realm metadata, then make sure path matching is turned on. | 5125 | // If no realm metadata, then make sure path matching is turned on. | ||
5126 | authinfo.verifyPath = (authinfo.realmValue.isEmpty()); | 5126 | authinfo.verifyPath = (authinfo.realmValue.isEmpty()); | ||
5127 | 5127 | | |||
5128 | const bool useCachedAuth = (m_request.responseCode == 401 || !config()->readEntry("no-preemptive-auth-reuse", false)); | 5128 | const bool useCachedAuth = (m_request.responseCode == 401 || !mapConfig().value(QStringLiteral("no-preemptive-auth-reuse"), false).toBool()); | ||
5129 | 5129 | | |||
5130 | if (useCachedAuth && checkCachedAuthentication(authinfo)) { | 5130 | if (useCachedAuth && checkCachedAuthentication(authinfo)) { | ||
5131 | const QByteArray cachedChallenge = config()->readEntry("www-auth-challenge", QByteArray()); | 5131 | const QByteArray cachedChallenge = mapConfig().value(QStringLiteral("www-auth-challenge"), QByteArray()).toByteArray(); | ||
5132 | if (!cachedChallenge.isEmpty()) { | 5132 | if (!cachedChallenge.isEmpty()) { | ||
5133 | m_wwwAuth = KAbstractHttpAuthentication::newAuth(cachedChallenge, config()); | 5133 | m_wwwAuth = KAbstractHttpAuthentication::newAuth(cachedChallenge, config()); | ||
5134 | if (m_wwwAuth) { | 5134 | if (m_wwwAuth) { | ||
5135 | qCDebug(KIO_HTTP) << "creating www authentication header from cached info"; | 5135 | qCDebug(KIO_HTTP) << "creating www authentication header from cached info"; | ||
5136 | m_wwwAuth->setChallenge(cachedChallenge, m_request.url, m_request.sentMethodString); | 5136 | m_wwwAuth->setChallenge(cachedChallenge, m_request.url, m_request.sentMethodString); | ||
5137 | m_wwwAuth->generateResponse(authinfo.username, authinfo.password); | 5137 | m_wwwAuth->generateResponse(authinfo.username, authinfo.password); | ||
5138 | } | 5138 | } | ||
5139 | } | 5139 | } | ||
5140 | } | 5140 | } | ||
5141 | } | 5141 | } | ||
5142 | 5142 | | |||
5143 | // If the internal meta-data "cached-proxy-auth" is set, then check for cached | 5143 | // If the internal meta-data "cached-proxy-auth" is set, then check for cached | ||
5144 | // authentication data and preemptively send the authentication header if a | 5144 | // authentication data and preemptively send the authentication header if a | ||
5145 | // matching one is found. | 5145 | // matching one is found. | ||
5146 | if (!m_proxyAuth && config()->readEntry("cached-proxy-auth", false)) { | 5146 | if (!m_proxyAuth && mapConfig().value(QStringLiteral("cached-proxy-auth"), false).toBool()) { | ||
5147 | KIO::AuthInfo authinfo; | 5147 | KIO::AuthInfo authinfo; | ||
5148 | authinfo.url = m_request.proxyUrl; | 5148 | authinfo.url = m_request.proxyUrl; | ||
5149 | authinfo.realmValue = config()->readEntry("proxy-auth-realm", QString()); | 5149 | authinfo.realmValue = mapConfig().value(QStringLiteral("proxy-auth-realm"), QString()).toString(); | ||
5150 | // If no realm metadata, then make sure path matching is turned on. | 5150 | // If no realm metadata, then make sure path matching is turned on. | ||
5151 | authinfo.verifyPath = (authinfo.realmValue.isEmpty()); | 5151 | authinfo.verifyPath = (authinfo.realmValue.isEmpty()); | ||
5152 | 5152 | | |||
5153 | if (checkCachedAuthentication(authinfo)) { | 5153 | if (checkCachedAuthentication(authinfo)) { | ||
5154 | const QByteArray cachedChallenge = config()->readEntry("proxy-auth-challenge", QByteArray()); | 5154 | const QByteArray cachedChallenge = mapConfig().value(QStringLiteral("proxy-auth-challenge"), QByteArray()).toByteArray(); | ||
5155 | if (!cachedChallenge.isEmpty()) { | 5155 | if (!cachedChallenge.isEmpty()) { | ||
5156 | m_proxyAuth = KAbstractHttpAuthentication::newAuth(cachedChallenge, config()); | 5156 | m_proxyAuth = KAbstractHttpAuthentication::newAuth(cachedChallenge, config()); | ||
5157 | if (m_proxyAuth) { | 5157 | if (m_proxyAuth) { | ||
5158 | qCDebug(KIO_HTTP) << "creating proxy authentication header from cached info"; | 5158 | qCDebug(KIO_HTTP) << "creating proxy authentication header from cached info"; | ||
5159 | m_proxyAuth->setChallenge(cachedChallenge, m_request.proxyUrl, m_request.sentMethodString); | 5159 | m_proxyAuth->setChallenge(cachedChallenge, m_request.proxyUrl, m_request.sentMethodString); | ||
5160 | m_proxyAuth->generateResponse(authinfo.username, authinfo.password); | 5160 | m_proxyAuth->generateResponse(authinfo.username, authinfo.password); | ||
5161 | } | 5161 | } | ||
5162 | } | 5162 | } | ||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Line(s) | |||||
5277 | void HTTPProtocol::saveAuthenticationData() | 5277 | void HTTPProtocol::saveAuthenticationData() | ||
5278 | { | 5278 | { | ||
5279 | KIO::AuthInfo authinfo; | 5279 | KIO::AuthInfo authinfo; | ||
5280 | bool alreadyCached = false; | 5280 | bool alreadyCached = false; | ||
5281 | KAbstractHttpAuthentication *auth = nullptr; | 5281 | KAbstractHttpAuthentication *auth = nullptr; | ||
5282 | switch (m_request.prevResponseCode) { | 5282 | switch (m_request.prevResponseCode) { | ||
5283 | case 401: | 5283 | case 401: | ||
5284 | auth = m_wwwAuth; | 5284 | auth = m_wwwAuth; | ||
5285 | alreadyCached = config()->readEntry("cached-www-auth", false); | 5285 | alreadyCached = mapConfig().value(QStringLiteral("cached-www-auth"), false).toBool(); | ||
5286 | break; | 5286 | break; | ||
5287 | case 407: | 5287 | case 407: | ||
5288 | auth = m_proxyAuth; | 5288 | auth = m_proxyAuth; | ||
5289 | alreadyCached = config()->readEntry("cached-proxy-auth", false); | 5289 | alreadyCached = mapConfig().value(QStringLiteral("cached-proxy-auth"), false).toBool(); | ||
5290 | break; | 5290 | break; | ||
5291 | default: | 5291 | default: | ||
5292 | Q_ASSERT(false); // should never happen! | 5292 | Q_ASSERT(false); // should never happen! | ||
5293 | } | 5293 | } | ||
5294 | 5294 | | |||
5295 | // Prevent recaching of the same credentials over and over again. | 5295 | // Prevent recaching of the same credentials over and over again. | ||
5296 | if (auth && (!auth->realm().isEmpty() || !alreadyCached)) { | 5296 | if (auth && (!auth->realm().isEmpty() || !alreadyCached)) { | ||
5297 | auth->fillKioAuthInfo(&authinfo); | 5297 | auth->fillKioAuthInfo(&authinfo); | ||
▲ Show 20 Lines • Show All 329 Lines • Show Last 20 Lines |