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 = configValue(QStringLiteral("Cookies"), false); | ||
447 | m_request.cacheTag.useCache = config()->readEntry("UseCache", true); | 447 | m_request.cacheTag.useCache = configValue(QStringLiteral("UseCache"), true); | ||
448 | m_request.preferErrorPage = config()->readEntry("errorPage", true); | 448 | m_request.preferErrorPage = configValue(QStringLiteral("errorPage"), true); | ||
449 | const bool noAuth = config()->readEntry("no-auth", false); | 449 | const bool noAuth = configValue(QStringLiteral("no-auth"), false); | ||
450 | m_request.doNotWWWAuthenticate = config()->readEntry("no-www-auth", noAuth); | 450 | m_request.doNotWWWAuthenticate = configValue(QStringLiteral("no-www-auth"), noAuth); | ||
451 | m_request.doNotProxyAuthenticate = config()->readEntry("no-proxy-auth", noAuth); | 451 | m_request.doNotProxyAuthenticate = configValue(QStringLiteral("no-proxy-auth"), noAuth); | ||
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 = configValue(QStringLiteral("MaxCacheAge"), DEFAULT_MAX_CACHE_AGE); | ||
454 | m_request.windowId = config()->readEntry("window-id"); | 454 | m_request.windowId = configValue(QStringLiteral("window-id")); | ||
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 (configValue(QStringLiteral("SendReferrer"), true) && | ||
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 (configValue(QStringLiteral("SendLanguageSettings"), true)) { | ||
483 | m_request.charsets = config()->readEntry("Charsets", DEFAULT_PARTIAL_CHARSET_HEADER); | 483 | m_request.charsets = configValue(QStringLiteral("Charsets"), QStringLiteral(DEFAULT_PARTIAL_CHARSET_HEADER)); | ||
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 = configValue(QStringLiteral("Languages"), QStringLiteral(DEFAULT_LANGUAGE_HEADER)); | ||
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 = configValue(QStringLiteral("DisablePassDlg"), false); | ||
515 | m_request.allowTransferCompression = config()->readEntry("AllowCompressedPage", true); | 515 | m_request.allowTransferCompression = configValue(QStringLiteral("AllowCompressedPage"), true); | ||
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 (configValue(QStringLiteral("SendUserAgent"), true)) { | ||
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 (configValue(QStringLiteral("DoNotTrack"), false)) { | ||
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 64 Lines • ▼ Show 20 Line(s) | |||||
2658 | infoMessage(i18n("%1 contacted. Waiting for reply...", m_request.url.host())); | 2658 | infoMessage(i18n("%1 contacted. Waiting for reply...", m_request.url.host())); | ||
2659 | 2659 | | |||
2660 | return res; | 2660 | return res; | ||
2661 | } | 2661 | } | ||
2662 | 2662 | | |||
2663 | void HTTPProtocol::forwardHttpResponseHeader(bool forwardImmediately) | 2663 | void HTTPProtocol::forwardHttpResponseHeader(bool forwardImmediately) | ||
2664 | { | 2664 | { | ||
2665 | // Send the response header if it was requested... | 2665 | // Send the response header if it was requested... | ||
2666 | if (!config()->readEntry("PropagateHttpHeader", false)) { | 2666 | if (!configValue(QStringLiteral("PropagateHttpHeader"), false)) { | ||
2667 | return; | 2667 | return; | ||
2668 | } | 2668 | } | ||
2669 | 2669 | | |||
2670 | setMetaData(QStringLiteral("HTTP-Headers"), m_responseHeaders.join(QLatin1Char('\n'))); | 2670 | setMetaData(QStringLiteral("HTTP-Headers"), m_responseHeaders.join(QLatin1Char('\n'))); | ||
2671 | 2671 | | |||
2672 | if (forwardImmediately) { | 2672 | if (forwardImmediately) { | ||
2673 | sendMetaData(); | 2673 | sendMetaData(); | ||
2674 | } | 2674 | } | ||
▲ Show 20 Lines • Show All 712 Lines • ▼ Show 20 Line(s) | 3109 | if (!noHeadersFound) { | |||
3387 | QByteArray cookieStr; // In case we get a cookie. | 3387 | QByteArray cookieStr; // In case we get a cookie. | ||
3388 | tIt = tokenizer.iterator("set-cookie"); | 3388 | tIt = tokenizer.iterator("set-cookie"); | ||
3389 | while (tIt.hasNext()) { | 3389 | while (tIt.hasNext()) { | ||
3390 | cookieStr += "Set-Cookie: " + tIt.next() + '\n'; | 3390 | cookieStr += "Set-Cookie: " + tIt.next() + '\n'; | ||
3391 | } | 3391 | } | ||
3392 | if (!cookieStr.isEmpty()) { | 3392 | if (!cookieStr.isEmpty()) { | ||
3393 | if ((m_request.cookieMode == HTTPRequest::CookiesAuto) && m_request.useCookieJar) { | 3393 | if ((m_request.cookieMode == HTTPRequest::CookiesAuto) && m_request.useCookieJar) { | ||
3394 | // Give cookies to the cookiejar. | 3394 | // Give cookies to the cookiejar. | ||
3395 | const QString domain = config()->readEntry("cross-domain"); | 3395 | const QString domain = configValue(QStringLiteral("cross-domain")); | ||
3396 | if (!domain.isEmpty() && isCrossDomainRequest(m_request.url.host(), domain)) { | 3396 | if (!domain.isEmpty() && isCrossDomainRequest(m_request.url.host(), domain)) { | ||
3397 | cookieStr = "Cross-Domain\n" + cookieStr; | 3397 | cookieStr = "Cross-Domain\n" + cookieStr; | ||
3398 | } | 3398 | } | ||
3399 | addCookies(m_request.url.toString(), cookieStr); | 3399 | addCookies(m_request.url.toString(), cookieStr); | ||
3400 | } else if (m_request.cookieMode == HTTPRequest::CookiesManual) { | 3400 | } else if (m_request.cookieMode == HTTPRequest::CookiesManual) { | ||
3401 | // Pass cookie to application | 3401 | // Pass cookie to application | ||
3402 | setMetaData(QStringLiteral("setcookies"), QString::fromUtf8(cookieStr)); // ## is encoding ok? | 3402 | setMetaData(QStringLiteral("setcookies"), QString::fromUtf8(cookieStr)); // ## is encoding ok? | ||
3403 | } | 3403 | } | ||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Line(s) | 3506 | if (m_request.cacheTag.policy == CC_Verify && | |||
3507 | m_request.cacheTag.plan(m_maxCacheAge) != CacheTag::UseCached) { | 3507 | m_request.cacheTag.plan(m_maxCacheAge) != CacheTag::UseCached) { | ||
3508 | qCDebug(KIO_HTTP) << "Reading resource from cache even though the cache plan is not " | 3508 | qCDebug(KIO_HTTP) << "Reading resource from cache even though the cache plan is not " | ||
3509 | "UseCached; the server is probably sending wrong expiry information."; | 3509 | "UseCached; the server is probably sending wrong expiry information."; | ||
3510 | } | 3510 | } | ||
3511 | // parseHeaderFromCache replaces this method in case of cached content | 3511 | // parseHeaderFromCache replaces this method in case of cached content | ||
3512 | return parseHeaderFromCache(); | 3512 | return parseHeaderFromCache(); | ||
3513 | } | 3513 | } | ||
3514 | 3514 | | |||
3515 | if (config()->readEntry("PropagateHttpHeader", false) || | 3515 | if (configValue(QStringLiteral("PropagateHttpHeader"), false) || | ||
3516 | m_request.cacheTag.ioMode == WriteToCache) { | 3516 | m_request.cacheTag.ioMode == WriteToCache) { | ||
3517 | // store header lines if they will be used; note that the tokenizer removing | 3517 | // store header lines if they will be used; note that the tokenizer removing | ||
3518 | // line continuation special cases is probably more good than bad. | 3518 | // line continuation special cases is probably more good than bad. | ||
3519 | int nextLinePos = 0; | 3519 | int nextLinePos = 0; | ||
3520 | int prevLinePos = 0; | 3520 | int prevLinePos = 0; | ||
3521 | bool haveMore = true; | 3521 | bool haveMore = true; | ||
3522 | while (haveMore) { | 3522 | while (haveMore) { | ||
3523 | haveMore = nextLine(buffer, &nextLinePos, bufPos); | 3523 | haveMore = nextLine(buffer, &nextLinePos, bufPos); | ||
▲ Show 20 Lines • Show All 243 Lines • ▼ Show 20 Line(s) | 3601 | { | |||
3767 | if (mayCache && m_request.responseCode == 200 && !m_mimeType.isEmpty()) { | 3767 | if (mayCache && m_request.responseCode == 200 && !m_mimeType.isEmpty()) { | ||
3768 | qCDebug(KIO_HTTP) << "Cache, adding" << m_request.url; | 3768 | qCDebug(KIO_HTTP) << "Cache, adding" << m_request.url; | ||
3769 | // ioMode can still be ReadFromCache here if we're performing a conditional get | 3769 | // ioMode can still be ReadFromCache here if we're performing a conditional get | ||
3770 | // aka validation | 3770 | // aka validation | ||
3771 | m_request.cacheTag.ioMode = WriteToCache; | 3771 | m_request.cacheTag.ioMode = WriteToCache; | ||
3772 | if (!cacheFileOpenWrite()) { | 3772 | if (!cacheFileOpenWrite()) { | ||
3773 | qCDebug(KIO_HTTP) << "Error creating cache entry for" << m_request.url << "!"; | 3773 | qCDebug(KIO_HTTP) << "Error creating cache entry for" << m_request.url << "!"; | ||
3774 | } | 3774 | } | ||
3775 | m_maxCacheSize = config()->readEntry("MaxCacheSize", DEFAULT_MAX_CACHE_SIZE); | 3775 | m_maxCacheSize = configValue(QStringLiteral("MaxCacheSize"), DEFAULT_MAX_CACHE_SIZE); | ||
3776 | } else if (m_request.responseCode == 304 && m_request.cacheTag.file) { | 3776 | } else if (m_request.responseCode == 304 && m_request.cacheTag.file) { | ||
3777 | if (!mayCache) { | 3777 | if (!mayCache) { | ||
3778 | qCDebug(KIO_HTTP) << "This webserver is confused about the cacheability of the data it sends."; | 3778 | qCDebug(KIO_HTTP) << "This webserver is confused about the cacheability of the data it sends."; | ||
3779 | } | 3779 | } | ||
3780 | // the cache file should still be open for reading, see satisfyRequestFromCache(). | 3780 | // the cache file should still be open for reading, see satisfyRequestFromCache(). | ||
3781 | Q_ASSERT(m_request.cacheTag.file->openMode() == QIODevice::ReadOnly); | 3781 | Q_ASSERT(m_request.cacheTag.file->openMode() == QIODevice::ReadOnly); | ||
3782 | Q_ASSERT(m_request.cacheTag.ioMode == ReadFromCache); | 3782 | Q_ASSERT(m_request.cacheTag.ioMode == ReadFromCache); | ||
3783 | } else { | 3783 | } else { | ||
▲ Show 20 Lines • Show All 1330 Lines • ▼ Show 20 Line(s) | |||||
5114 | 5114 | | |||
5115 | QString HTTPProtocol::authenticationHeader() | 5115 | QString HTTPProtocol::authenticationHeader() | ||
5116 | { | 5116 | { | ||
5117 | QByteArray ret; | 5117 | QByteArray ret; | ||
5118 | 5118 | | |||
5119 | // If the internal meta-data "cached-www-auth" is set, then check for cached | 5119 | // If the internal meta-data "cached-www-auth" is set, then check for cached | ||
5120 | // authentication data and preemptively send the authentication header if a | 5120 | // authentication data and preemptively send the authentication header if a | ||
5121 | // matching one is found. | 5121 | // matching one is found. | ||
5122 | if (!m_wwwAuth && config()->readEntry("cached-www-auth", false)) { | 5122 | if (!m_wwwAuth && configValue(QStringLiteral("cached-www-auth"), false)) { | ||
5123 | KIO::AuthInfo authinfo; | 5123 | KIO::AuthInfo authinfo; | ||
5124 | authinfo.url = m_request.url; | 5124 | authinfo.url = m_request.url; | ||
5125 | authinfo.realmValue = config()->readEntry("www-auth-realm", QString()); | 5125 | authinfo.realmValue = configValue(QStringLiteral("www-auth-realm"), QString()); | ||
5126 | // If no realm metadata, then make sure path matching is turned on. | 5126 | // If no realm metadata, then make sure path matching is turned on. | ||
5127 | authinfo.verifyPath = (authinfo.realmValue.isEmpty()); | 5127 | authinfo.verifyPath = (authinfo.realmValue.isEmpty()); | ||
5128 | 5128 | | |||
5129 | const bool useCachedAuth = (m_request.responseCode == 401 || !config()->readEntry("no-preemptive-auth-reuse", false)); | 5129 | const bool useCachedAuth = (m_request.responseCode == 401 || !configValue(QStringLiteral("no-preemptive-auth-reuse"), false)); | ||
5130 | 5130 | | |||
5131 | if (useCachedAuth && checkCachedAuthentication(authinfo)) { | 5131 | if (useCachedAuth && checkCachedAuthentication(authinfo)) { | ||
5132 | const QByteArray cachedChallenge = config()->readEntry("www-auth-challenge", QByteArray()); | 5132 | const QByteArray cachedChallenge = mapConfig().value(QStringLiteral("www-auth-challenge"), QByteArray()).toByteArray(); | ||
5133 | if (!cachedChallenge.isEmpty()) { | 5133 | if (!cachedChallenge.isEmpty()) { | ||
5134 | m_wwwAuth = KAbstractHttpAuthentication::newAuth(cachedChallenge, config()); | 5134 | m_wwwAuth = KAbstractHttpAuthentication::newAuth(cachedChallenge, config()); | ||
5135 | if (m_wwwAuth) { | 5135 | if (m_wwwAuth) { | ||
5136 | qCDebug(KIO_HTTP) << "creating www authentication header from cached info"; | 5136 | qCDebug(KIO_HTTP) << "creating www authentication header from cached info"; | ||
5137 | m_wwwAuth->setChallenge(cachedChallenge, m_request.url, m_request.sentMethodString); | 5137 | m_wwwAuth->setChallenge(cachedChallenge, m_request.url, m_request.sentMethodString); | ||
5138 | m_wwwAuth->generateResponse(authinfo.username, authinfo.password); | 5138 | m_wwwAuth->generateResponse(authinfo.username, authinfo.password); | ||
5139 | } | 5139 | } | ||
5140 | } | 5140 | } | ||
5141 | } | 5141 | } | ||
5142 | } | 5142 | } | ||
5143 | 5143 | | |||
5144 | // If the internal meta-data "cached-proxy-auth" is set, then check for cached | 5144 | // If the internal meta-data "cached-proxy-auth" is set, then check for cached | ||
5145 | // authentication data and preemptively send the authentication header if a | 5145 | // authentication data and preemptively send the authentication header if a | ||
5146 | // matching one is found. | 5146 | // matching one is found. | ||
5147 | if (!m_proxyAuth && config()->readEntry("cached-proxy-auth", false)) { | 5147 | if (!m_proxyAuth && configValue(QStringLiteral("cached-proxy-auth"), false)) { | ||
5148 | KIO::AuthInfo authinfo; | 5148 | KIO::AuthInfo authinfo; | ||
5149 | authinfo.url = m_request.proxyUrl; | 5149 | authinfo.url = m_request.proxyUrl; | ||
5150 | authinfo.realmValue = config()->readEntry("proxy-auth-realm", QString()); | 5150 | authinfo.realmValue = configValue(QStringLiteral("proxy-auth-realm"), QString()); | ||
5151 | // If no realm metadata, then make sure path matching is turned on. | 5151 | // If no realm metadata, then make sure path matching is turned on. | ||
5152 | authinfo.verifyPath = (authinfo.realmValue.isEmpty()); | 5152 | authinfo.verifyPath = (authinfo.realmValue.isEmpty()); | ||
5153 | 5153 | | |||
5154 | if (checkCachedAuthentication(authinfo)) { | 5154 | if (checkCachedAuthentication(authinfo)) { | ||
5155 | const QByteArray cachedChallenge = config()->readEntry("proxy-auth-challenge", QByteArray()); | 5155 | const QByteArray cachedChallenge = mapConfig().value(QStringLiteral("proxy-auth-challenge"), QByteArray()).toByteArray(); | ||
5156 | if (!cachedChallenge.isEmpty()) { | 5156 | if (!cachedChallenge.isEmpty()) { | ||
5157 | m_proxyAuth = KAbstractHttpAuthentication::newAuth(cachedChallenge, config()); | 5157 | m_proxyAuth = KAbstractHttpAuthentication::newAuth(cachedChallenge, config()); | ||
5158 | if (m_proxyAuth) { | 5158 | if (m_proxyAuth) { | ||
5159 | qCDebug(KIO_HTTP) << "creating proxy authentication header from cached info"; | 5159 | qCDebug(KIO_HTTP) << "creating proxy authentication header from cached info"; | ||
5160 | m_proxyAuth->setChallenge(cachedChallenge, m_request.proxyUrl, m_request.sentMethodString); | 5160 | m_proxyAuth->setChallenge(cachedChallenge, m_request.proxyUrl, m_request.sentMethodString); | ||
5161 | m_proxyAuth->generateResponse(authinfo.username, authinfo.password); | 5161 | m_proxyAuth->generateResponse(authinfo.username, authinfo.password); | ||
5162 | } | 5162 | } | ||
5163 | } | 5163 | } | ||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Line(s) | |||||
5278 | void HTTPProtocol::saveAuthenticationData() | 5278 | void HTTPProtocol::saveAuthenticationData() | ||
5279 | { | 5279 | { | ||
5280 | KIO::AuthInfo authinfo; | 5280 | KIO::AuthInfo authinfo; | ||
5281 | bool alreadyCached = false; | 5281 | bool alreadyCached = false; | ||
5282 | KAbstractHttpAuthentication *auth = nullptr; | 5282 | KAbstractHttpAuthentication *auth = nullptr; | ||
5283 | switch (m_request.prevResponseCode) { | 5283 | switch (m_request.prevResponseCode) { | ||
5284 | case 401: | 5284 | case 401: | ||
5285 | auth = m_wwwAuth; | 5285 | auth = m_wwwAuth; | ||
5286 | alreadyCached = config()->readEntry("cached-www-auth", false); | 5286 | alreadyCached = configValue(QStringLiteral("cached-www-auth"), false); | ||
5287 | break; | 5287 | break; | ||
5288 | case 407: | 5288 | case 407: | ||
5289 | auth = m_proxyAuth; | 5289 | auth = m_proxyAuth; | ||
5290 | alreadyCached = config()->readEntry("cached-proxy-auth", false); | 5290 | alreadyCached = configValue(QStringLiteral("cached-proxy-auth"), false); | ||
5291 | break; | 5291 | break; | ||
5292 | default: | 5292 | default: | ||
5293 | Q_ASSERT(false); // should never happen! | 5293 | Q_ASSERT(false); // should never happen! | ||
5294 | } | 5294 | } | ||
5295 | 5295 | | |||
5296 | // Prevent recaching of the same credentials over and over again. | 5296 | // Prevent recaching of the same credentials over and over again. | ||
5297 | if (auth && (!auth->realm().isEmpty() || !alreadyCached)) { | 5297 | if (auth && (!auth->realm().isEmpty() || !alreadyCached)) { | ||
5298 | auth->fillKioAuthInfo(&authinfo); | 5298 | auth->fillKioAuthInfo(&authinfo); | ||
▲ Show 20 Lines • Show All 329 Lines • Show Last 20 Lines |