qnetworkaccesscachebackend.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/network/access/qnetworkaccesscachebackend.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtNetwork module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
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 http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://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 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34//#define QNETWORKACCESSCACHEBACKEND_DEBUG-
35-
36#include "qnetworkaccesscachebackend_p.h"-
37#include "qabstractnetworkcache.h"-
38#include "qfileinfo.h"-
39#include "qurlinfo_p.h"-
40#include "qdir.h"-
41#include "qcoreapplication.h"-
42-
43QT_BEGIN_NAMESPACE-
44-
45QNetworkAccessCacheBackend::QNetworkAccessCacheBackend()-
46 : QNetworkAccessBackend()-
47{-
48}
executed 14 times by 3 tests: end of block
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkAccessManager
  • tst_QNetworkReply
14
49-
50QNetworkAccessCacheBackend::~QNetworkAccessCacheBackend()-
51{-
52}-
53-
54void QNetworkAccessCacheBackend::open()-
55{-
56 if (operation() != QNetworkAccessManager::GetOperation || !sendCacheContents()) {
operation() !=...::GetOperationDescription
TRUEnever evaluated
FALSEevaluated 13 times by 2 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
!sendCacheContents()Description
TRUEevaluated 4 times by 2 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
FALSEevaluated 9 times by 2 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
0-13
57 QString msg = QCoreApplication::translate("QNetworkAccessCacheBackend", "Error opening %1")-
58 .arg(this->url().toString());-
59 error(QNetworkReply::ContentNotFoundError, msg);-
60 } else {
executed 4 times by 2 tests: end of block
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
4
61 setAttribute(QNetworkRequest::SourceIsFromCacheAttribute, true);-
62 }
executed 9 times by 2 tests: end of block
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
9
63 finished();-
64}
executed 13 times by 2 tests: end of block
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
13
65-
66bool QNetworkAccessCacheBackend::sendCacheContents()-
67{-
68 setCachingEnabled(false);-
69 QAbstractNetworkCache *nc = networkCache();-
70 if (!nc)
!ncDescription
TRUEnever evaluated
FALSEevaluated 13 times by 2 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
0-13
71 return false;
never executed: return false;
0
72-
73 QNetworkCacheMetaData item = nc->metaData(url());-
74 if (!item.isValid())
!item.isValid()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QAbstractNetworkCache
FALSEevaluated 12 times by 2 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
1-12
75 return false;
executed 1 time by 1 test: return false;
Executed by:
  • tst_QAbstractNetworkCache
1
76-
77 QNetworkCacheMetaData::AttributesMap attributes = item.attributes();-
78 setAttribute(QNetworkRequest::HttpStatusCodeAttribute, attributes.value(QNetworkRequest::HttpStatusCodeAttribute));-
79 setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, attributes.value(QNetworkRequest::HttpReasonPhraseAttribute));-
80-
81 // set the raw headers-
82 QNetworkCacheMetaData::RawHeaderList rawHeaders = item.rawHeaders();-
83 QNetworkCacheMetaData::RawHeaderList::ConstIterator it = rawHeaders.constBegin(),-
84 end = rawHeaders.constEnd();-
85 for ( ; it != end; ++it) {
it != endDescription
TRUEevaluated 39 times by 2 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
FALSEevaluated 9 times by 2 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
9-39
86 if (it->first.toLower() == "cache-control" &&
it->first.toLo...cache-control"Description
TRUEevaluated 5 times by 2 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
FALSEevaluated 34 times by 2 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
5-34
87 it->second.toLower().contains("must-revalidate")) {
it->second.toL...t-revalidate")Description
TRUEevaluated 3 times by 2 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QNetworkReply
2-3
88 return false;
executed 3 times by 2 tests: return false;
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
3
89 }-
90 setRawHeader(it->first, it->second);-
91 }
executed 36 times by 2 tests: end of block
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
36
92-
93 // handle a possible redirect-
94 QVariant redirectionTarget = attributes.value(QNetworkRequest::RedirectionTargetAttribute);-
95 if (redirectionTarget.isValid()) {
redirectionTarget.isValid()Description
TRUEnever evaluated
FALSEevaluated 9 times by 2 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
0-9
96 setAttribute(QNetworkRequest::RedirectionTargetAttribute, redirectionTarget);-
97 redirectionRequested(redirectionTarget.toUrl());-
98 }
never executed: end of block
0
99-
100 // signal we're open-
101 metaDataChanged();-
102-
103 if (operation() == QNetworkAccessManager::GetOperation) {
operation() ==...::GetOperationDescription
TRUEevaluated 9 times by 2 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
FALSEnever evaluated
0-9
104 QIODevice *contents = nc->data(url());-
105 if (!contents)
!contentsDescription
TRUEnever evaluated
FALSEevaluated 9 times by 2 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
0-9
106 return false;
never executed: return false;
0
107 contents->setParent(this);-
108 writeDownstreamData(contents);-
109 }
executed 9 times by 2 tests: end of block
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
9
110-
111#if defined(QNETWORKACCESSCACHEBACKEND_DEBUG)-
112 qDebug() << "Successfully sent cache:" << url();-
113#endif-
114 return true;
executed 9 times by 2 tests: return true;
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QNetworkReply
9
115}-
116-
117void QNetworkAccessCacheBackend::closeDownstreamChannel()-
118{-
119}-
120-
121void QNetworkAccessCacheBackend::closeUpstreamChannel()-
122{-
123 Q_ASSERT_X(false, Q_FUNC_INFO, "This function show not have been called!");-
124}
never executed: end of block
0
125-
126void QNetworkAccessCacheBackend::upstreamReadyRead()-
127{-
128 Q_ASSERT_X(false, Q_FUNC_INFO, "This function show not have been called!");-
129}
never executed: end of block
0
130-
131void QNetworkAccessCacheBackend::downstreamReadyWrite()-
132{-
133 Q_ASSERT_X(false, Q_FUNC_INFO, "This function show not have been called!");-
134}
never executed: end of block
0
135-
136QT_END_NAMESPACE-
137-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9