| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/access/qnetworkaccesscachebackend.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
| 5 | ** | - | ||||||||||||
| 6 | ** This file is part of the QtNetwork module of the Qt Toolkit. | - | ||||||||||||
| 7 | ** | - | ||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||
| 16 | ** | - | ||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
| 24 | ** | - | ||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
| 35 | ** | - | ||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 37 | ** | - | ||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | //#define QNETWORKACCESSCACHEBACKEND_DEBUG | - | ||||||||||||
| 41 | - | |||||||||||||
| 42 | #include "qnetworkaccesscachebackend_p.h" | - | ||||||||||||
| 43 | #include "qabstractnetworkcache.h" | - | ||||||||||||
| 44 | #include "qfileinfo.h" | - | ||||||||||||
| 45 | #include "qurlinfo_p.h" | - | ||||||||||||
| 46 | #include "qdir.h" | - | ||||||||||||
| 47 | #include "qcoreapplication.h" | - | ||||||||||||
| 48 | - | |||||||||||||
| 49 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 50 | - | |||||||||||||
| 51 | QNetworkAccessCacheBackend::QNetworkAccessCacheBackend() | - | ||||||||||||
| 52 | : QNetworkAccessBackend() | - | ||||||||||||
| 53 | { | - | ||||||||||||
| 54 | } executed 14 times by 3 tests: end of blockExecuted by:
| 14 | ||||||||||||
| 55 | - | |||||||||||||
| 56 | QNetworkAccessCacheBackend::~QNetworkAccessCacheBackend() | - | ||||||||||||
| 57 | { | - | ||||||||||||
| 58 | } | - | ||||||||||||
| 59 | - | |||||||||||||
| 60 | void QNetworkAccessCacheBackend::open() | - | ||||||||||||
| 61 | { | - | ||||||||||||
| 62 | if (operation() != QNetworkAccessManager::GetOperation || !sendCacheContents()) {
| 0-13 | ||||||||||||
| 63 | QString msg = QCoreApplication::translate("QNetworkAccessCacheBackend", "Error opening %1") | - | ||||||||||||
| 64 | .arg(this->url().toString()); | - | ||||||||||||
| 65 | error(QNetworkReply::ContentNotFoundError, msg); | - | ||||||||||||
| 66 | } else { executed 4 times by 2 tests: end of blockExecuted by:
| 4 | ||||||||||||
| 67 | setAttribute(QNetworkRequest::SourceIsFromCacheAttribute, true); | - | ||||||||||||
| 68 | } executed 9 times by 2 tests: end of blockExecuted by:
| 9 | ||||||||||||
| 69 | finished(); | - | ||||||||||||
| 70 | } executed 13 times by 2 tests: end of blockExecuted by:
| 13 | ||||||||||||
| 71 | - | |||||||||||||
| 72 | bool QNetworkAccessCacheBackend::sendCacheContents() | - | ||||||||||||
| 73 | { | - | ||||||||||||
| 74 | setCachingEnabled(false); | - | ||||||||||||
| 75 | QAbstractNetworkCache *nc = networkCache(); | - | ||||||||||||
| 76 | if (!nc)
| 0-13 | ||||||||||||
| 77 | return false; never executed: return false; | 0 | ||||||||||||
| 78 | - | |||||||||||||
| 79 | QNetworkCacheMetaData item = nc->metaData(url()); | - | ||||||||||||
| 80 | if (!item.isValid())
| 1-12 | ||||||||||||
| 81 | return false; executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||
| 82 | - | |||||||||||||
| 83 | QNetworkCacheMetaData::AttributesMap attributes = item.attributes(); | - | ||||||||||||
| 84 | setAttribute(QNetworkRequest::HttpStatusCodeAttribute, attributes.value(QNetworkRequest::HttpStatusCodeAttribute)); | - | ||||||||||||
| 85 | setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, attributes.value(QNetworkRequest::HttpReasonPhraseAttribute)); | - | ||||||||||||
| 86 | - | |||||||||||||
| 87 | // set the raw headers | - | ||||||||||||
| 88 | QNetworkCacheMetaData::RawHeaderList rawHeaders = item.rawHeaders(); | - | ||||||||||||
| 89 | QNetworkCacheMetaData::RawHeaderList::ConstIterator it = rawHeaders.constBegin(), | - | ||||||||||||
| 90 | end = rawHeaders.constEnd(); | - | ||||||||||||
| 91 | for ( ; it != end; ++it) {
| 9-39 | ||||||||||||
| 92 | if (it->first.toLower() == "cache-control" &&
| 5-34 | ||||||||||||
| 93 | it->second.toLower().contains("must-revalidate")) {
| 2-3 | ||||||||||||
| 94 | return false; executed 3 times by 2 tests: return false;Executed by:
| 3 | ||||||||||||
| 95 | } | - | ||||||||||||
| 96 | setRawHeader(it->first, it->second); | - | ||||||||||||
| 97 | } executed 36 times by 2 tests: end of blockExecuted by:
| 36 | ||||||||||||
| 98 | - | |||||||||||||
| 99 | // handle a possible redirect | - | ||||||||||||
| 100 | QVariant redirectionTarget = attributes.value(QNetworkRequest::RedirectionTargetAttribute); | - | ||||||||||||
| 101 | if (redirectionTarget.isValid()) {
| 0-9 | ||||||||||||
| 102 | setAttribute(QNetworkRequest::RedirectionTargetAttribute, redirectionTarget); | - | ||||||||||||
| 103 | redirectionRequested(redirectionTarget.toUrl()); | - | ||||||||||||
| 104 | } never executed: end of block | 0 | ||||||||||||
| 105 | - | |||||||||||||
| 106 | // signal we're open | - | ||||||||||||
| 107 | metaDataChanged(); | - | ||||||||||||
| 108 | - | |||||||||||||
| 109 | if (operation() == QNetworkAccessManager::GetOperation) {
| 0-9 | ||||||||||||
| 110 | QIODevice *contents = nc->data(url()); | - | ||||||||||||
| 111 | if (!contents)
| 0-9 | ||||||||||||
| 112 | return false; never executed: return false; | 0 | ||||||||||||
| 113 | contents->setParent(this); | - | ||||||||||||
| 114 | writeDownstreamData(contents); | - | ||||||||||||
| 115 | } executed 9 times by 2 tests: end of blockExecuted by:
| 9 | ||||||||||||
| 116 | - | |||||||||||||
| 117 | #if defined(QNETWORKACCESSCACHEBACKEND_DEBUG) | - | ||||||||||||
| 118 | qDebug() << "Successfully sent cache:" << url(); | - | ||||||||||||
| 119 | #endif | - | ||||||||||||
| 120 | return true; executed 9 times by 2 tests: return true;Executed by:
| 9 | ||||||||||||
| 121 | } | - | ||||||||||||
| 122 | - | |||||||||||||
| 123 | void QNetworkAccessCacheBackend::closeDownstreamChannel() | - | ||||||||||||
| 124 | { | - | ||||||||||||
| 125 | } | - | ||||||||||||
| 126 | - | |||||||||||||
| 127 | void QNetworkAccessCacheBackend::closeUpstreamChannel() | - | ||||||||||||
| 128 | { | - | ||||||||||||
| 129 | Q_ASSERT_X(false, Q_FUNC_INFO, "This function show not have been called!"); | - | ||||||||||||
| 130 | } never executed: end of block | 0 | ||||||||||||
| 131 | - | |||||||||||||
| 132 | void QNetworkAccessCacheBackend::upstreamReadyRead() | - | ||||||||||||
| 133 | { | - | ||||||||||||
| 134 | Q_ASSERT_X(false, Q_FUNC_INFO, "This function show not have been called!"); | - | ||||||||||||
| 135 | } never executed: end of block | 0 | ||||||||||||
| 136 | - | |||||||||||||
| 137 | void QNetworkAccessCacheBackend::downstreamReadyWrite() | - | ||||||||||||
| 138 | { | - | ||||||||||||
| 139 | Q_ASSERT_X(false, Q_FUNC_INFO, "This function show not have been called!"); | - | ||||||||||||
| 140 | } never executed: end of block | 0 | ||||||||||||
| 141 | - | |||||||||||||
| 142 | QT_END_NAMESPACE | - | ||||||||||||
| 143 | - | |||||||||||||
| Source code | Switch to Preprocessed file |