Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/access/qnetworkreplyhttpimpl.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 QNETWORKACCESSHTTPBACKEND_DEBUG | - | ||||||||||||||||||
35 | - | |||||||||||||||||||
36 | #include "qnetworkreplyhttpimpl_p.h" | - | ||||||||||||||||||
37 | #include "qnetworkaccessmanager_p.h" | - | ||||||||||||||||||
38 | #include "qnetworkaccesscache_p.h" | - | ||||||||||||||||||
39 | #include "qabstractnetworkcache.h" | - | ||||||||||||||||||
40 | #include "qnetworkrequest.h" | - | ||||||||||||||||||
41 | #include "qnetworkreply.h" | - | ||||||||||||||||||
42 | #include "qnetworkrequest_p.h" | - | ||||||||||||||||||
43 | #include "qnetworkcookie.h" | - | ||||||||||||||||||
44 | #include "qnetworkcookie_p.h" | - | ||||||||||||||||||
45 | #include "QtCore/qdatetime.h" | - | ||||||||||||||||||
46 | #include "QtCore/qelapsedtimer.h" | - | ||||||||||||||||||
47 | #include "QtNetwork/qsslconfiguration.h" | - | ||||||||||||||||||
48 | #include "qhttpthreaddelegate_p.h" | - | ||||||||||||||||||
49 | #include "qthread.h" | - | ||||||||||||||||||
50 | #include "QtCore/qcoreapplication.h" | - | ||||||||||||||||||
51 | - | |||||||||||||||||||
52 | #include <QtCore/private/qthread_p.h> | - | ||||||||||||||||||
53 | - | |||||||||||||||||||
54 | #include "qnetworkcookiejar.h" | - | ||||||||||||||||||
55 | - | |||||||||||||||||||
56 | #ifndef QT_NO_HTTP | - | ||||||||||||||||||
57 | - | |||||||||||||||||||
58 | #include <string.h> // for strchr | - | ||||||||||||||||||
59 | - | |||||||||||||||||||
60 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
61 | - | |||||||||||||||||||
62 | class QNetworkProxy; | - | ||||||||||||||||||
63 | - | |||||||||||||||||||
64 | static inline bool isSeparator(char c) | - | ||||||||||||||||||
65 | { | - | ||||||||||||||||||
66 | static const char separators[] = "()<>@,;:\\\"/[]?={}"; | - | ||||||||||||||||||
67 | return isLWS(c) || strchr(separators, c) != 0; executed 157 times by 2 tests: return isLWS(c) || strchr(separators, c) != 0; Executed by:
| 0-157 | ||||||||||||||||||
68 | } | - | ||||||||||||||||||
69 | - | |||||||||||||||||||
70 | // ### merge with nextField in cookiejar.cpp | - | ||||||||||||||||||
71 | static QHash<QByteArray, QByteArray> parseHttpOptionHeader(const QByteArray &header) | - | ||||||||||||||||||
72 | { | - | ||||||||||||||||||
73 | // The HTTP header is of the form: | - | ||||||||||||||||||
74 | // header = #1(directives) | - | ||||||||||||||||||
75 | // directives = token | value-directive | - | ||||||||||||||||||
76 | // value-directive = token "=" (token | quoted-string) | - | ||||||||||||||||||
77 | QHash<QByteArray, QByteArray> result; | - | ||||||||||||||||||
78 | - | |||||||||||||||||||
79 | int pos = 0; | - | ||||||||||||||||||
80 | while (true) { | - | ||||||||||||||||||
81 | // skip spaces | - | ||||||||||||||||||
82 | pos = nextNonWhitespace(header, pos); | - | ||||||||||||||||||
83 | if (pos == header.length())
| 22-69 | ||||||||||||||||||
84 | return result; // end of parsing executed 22 times by 2 tests: return result; Executed by:
| 22 | ||||||||||||||||||
85 | - | |||||||||||||||||||
86 | // pos points to a non-whitespace | - | ||||||||||||||||||
87 | int comma = header.indexOf(',', pos); | - | ||||||||||||||||||
88 | int equal = header.indexOf('=', pos); | - | ||||||||||||||||||
89 | if (comma == pos || equal == pos)
| 0-69 | ||||||||||||||||||
90 | // huh? Broken header. | - | ||||||||||||||||||
91 | return result; never executed: return result; | 0 | ||||||||||||||||||
92 | - | |||||||||||||||||||
93 | // The key name is delimited by either a comma, an equal sign or the end | - | ||||||||||||||||||
94 | // of the header, whichever comes first | - | ||||||||||||||||||
95 | int end = comma; | - | ||||||||||||||||||
96 | if (end == -1)
| 19-50 | ||||||||||||||||||
97 | end = header.length(); executed 50 times by 2 tests: end = header.length(); Executed by:
| 50 | ||||||||||||||||||
98 | if (equal != -1 && end > equal)
| 4-47 | ||||||||||||||||||
99 | end = equal; // equal sign comes before comma/end executed 43 times by 2 tests: end = equal; Executed by:
| 43 | ||||||||||||||||||
100 | QByteArray key = QByteArray(header.constData() + pos, end - pos).trimmed().toLower(); | - | ||||||||||||||||||
101 | pos = end + 1; | - | ||||||||||||||||||
102 | - | |||||||||||||||||||
103 | if (uint(equal) < uint(comma)) {
| 26-43 | ||||||||||||||||||
104 | // case: token "=" (token | quoted-string) | - | ||||||||||||||||||
105 | // skip spaces | - | ||||||||||||||||||
106 | pos = nextNonWhitespace(header, pos); | - | ||||||||||||||||||
107 | if (pos == header.length())
| 0-43 | ||||||||||||||||||
108 | // huh? Broken header | - | ||||||||||||||||||
109 | return result; never executed: return result; | 0 | ||||||||||||||||||
110 | - | |||||||||||||||||||
111 | QByteArray value; | - | ||||||||||||||||||
112 | value.reserve(header.length() - pos); | - | ||||||||||||||||||
113 | if (header.at(pos) == '"') {
| 0-43 | ||||||||||||||||||
114 | // case: quoted-string | - | ||||||||||||||||||
115 | // quoted-string = ( <"> *(qdtext | quoted-pair ) <"> ) | - | ||||||||||||||||||
116 | // qdtext = <any TEXT except <">> | - | ||||||||||||||||||
117 | // quoted-pair = "\" CHAR | - | ||||||||||||||||||
118 | ++pos; | - | ||||||||||||||||||
119 | while (pos < header.length()) {
| 0 | ||||||||||||||||||
120 | char c = header.at(pos); | - | ||||||||||||||||||
121 | if (c == '"') {
| 0 | ||||||||||||||||||
122 | // end of quoted text | - | ||||||||||||||||||
123 | break; never executed: break; | 0 | ||||||||||||||||||
124 | } else if (c == '\\') {
| 0 | ||||||||||||||||||
125 | ++pos; | - | ||||||||||||||||||
126 | if (pos >= header.length())
| 0 | ||||||||||||||||||
127 | // broken header | - | ||||||||||||||||||
128 | return result; never executed: return result; | 0 | ||||||||||||||||||
129 | c = header.at(pos); | - | ||||||||||||||||||
130 | } never executed: end of block | 0 | ||||||||||||||||||
131 | - | |||||||||||||||||||
132 | value += c; | - | ||||||||||||||||||
133 | ++pos; | - | ||||||||||||||||||
134 | } never executed: end of block | 0 | ||||||||||||||||||
135 | } else { never executed: end of block | 0 | ||||||||||||||||||
136 | // case: token | - | ||||||||||||||||||
137 | while (pos < header.length()) {
| 28-157 | ||||||||||||||||||
138 | char c = header.at(pos); | - | ||||||||||||||||||
139 | if (isSeparator(c))
| 15-142 | ||||||||||||||||||
140 | break; executed 15 times by 2 tests: break; Executed by:
| 15 | ||||||||||||||||||
141 | value += c; | - | ||||||||||||||||||
142 | ++pos; | - | ||||||||||||||||||
143 | } executed 142 times by 2 tests: end of block Executed by:
| 142 | ||||||||||||||||||
144 | } executed 43 times by 2 tests: end of block Executed by:
| 43 | ||||||||||||||||||
145 | - | |||||||||||||||||||
146 | result.insert(key, value); | - | ||||||||||||||||||
147 | - | |||||||||||||||||||
148 | // find the comma now: | - | ||||||||||||||||||
149 | comma = header.indexOf(',', pos); | - | ||||||||||||||||||
150 | if (comma == -1)
| 15-28 | ||||||||||||||||||
151 | return result; // end of parsing executed 28 times by 2 tests: return result; Executed by:
| 28 | ||||||||||||||||||
152 | pos = comma + 1; | - | ||||||||||||||||||
153 | } else { executed 15 times by 2 tests: end of block Executed by:
| 15 | ||||||||||||||||||
154 | // case: token | - | ||||||||||||||||||
155 | // key is already set | - | ||||||||||||||||||
156 | result.insert(key, QByteArray()); | - | ||||||||||||||||||
157 | } executed 26 times by 2 tests: end of block Executed by:
| 26 | ||||||||||||||||||
158 | } | - | ||||||||||||||||||
159 | } never executed: end of block | 0 | ||||||||||||||||||
160 | - | |||||||||||||||||||
161 | QNetworkReplyHttpImpl::QNetworkReplyHttpImpl(QNetworkAccessManager* const manager, | - | ||||||||||||||||||
162 | const QNetworkRequest& request, | - | ||||||||||||||||||
163 | QNetworkAccessManager::Operation& operation, | - | ||||||||||||||||||
164 | QIODevice* outgoingData) | - | ||||||||||||||||||
165 | : QNetworkReply(*new QNetworkReplyHttpImplPrivate, manager) | - | ||||||||||||||||||
166 | { | - | ||||||||||||||||||
167 | Q_D(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
168 | d->manager = manager; | - | ||||||||||||||||||
169 | d->managerPrivate = manager->d_func(); | - | ||||||||||||||||||
170 | d->request = request; | - | ||||||||||||||||||
171 | d->originalRequest = request; | - | ||||||||||||||||||
172 | d->operation = operation; | - | ||||||||||||||||||
173 | d->outgoingData = outgoingData; | - | ||||||||||||||||||
174 | d->url = request.url(); | - | ||||||||||||||||||
175 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
176 | d->sslConfiguration = request.sslConfiguration(); | - | ||||||||||||||||||
177 | #endif | - | ||||||||||||||||||
178 | - | |||||||||||||||||||
179 | // FIXME Later maybe set to Unbuffered, especially if it is zerocopy or from cache? | - | ||||||||||||||||||
180 | QIODevice::open(QIODevice::ReadOnly); | - | ||||||||||||||||||
181 | - | |||||||||||||||||||
182 | - | |||||||||||||||||||
183 | // Internal code that does a HTTP reply for the synchronous Ajax | - | ||||||||||||||||||
184 | // in Qt WebKit. | - | ||||||||||||||||||
185 | QVariant synchronousHttpAttribute = request.attribute( | - | ||||||||||||||||||
186 | static_cast<QNetworkRequest::Attribute>(QNetworkRequest::SynchronousRequestAttribute)); | - | ||||||||||||||||||
187 | if (synchronousHttpAttribute.isValid()) {
| 76-811 | ||||||||||||||||||
188 | d->synchronous = synchronousHttpAttribute.toBool(); | - | ||||||||||||||||||
189 | if (d->synchronous && outgoingData) {
| 0-76 | ||||||||||||||||||
190 | // The synchronous HTTP is a corner case, we will put all upload data in one big QByteArray in the outgoingDataBuffer. | - | ||||||||||||||||||
191 | // Yes, this is not the most efficient thing to do, but on the other hand synchronous XHR needs to die anyway. | - | ||||||||||||||||||
192 | d->outgoingDataBuffer = QSharedPointer<QRingBuffer>::create(); | - | ||||||||||||||||||
193 | qint64 previousDataSize = 0; | - | ||||||||||||||||||
194 | do { | - | ||||||||||||||||||
195 | previousDataSize = d->outgoingDataBuffer->size(); | - | ||||||||||||||||||
196 | d->outgoingDataBuffer->append(d->outgoingData->readAll()); | - | ||||||||||||||||||
197 | } while (d->outgoingDataBuffer->size() != previousDataSize); executed 77 times by 1 test: end of block Executed by:
| 36-77 | ||||||||||||||||||
198 | d->_q_startOperation(); | - | ||||||||||||||||||
199 | return; executed 41 times by 1 test: return; Executed by:
| 41 | ||||||||||||||||||
200 | } | - | ||||||||||||||||||
201 | } executed 35 times by 1 test: end of block Executed by:
| 35 | ||||||||||||||||||
202 | - | |||||||||||||||||||
203 | - | |||||||||||||||||||
204 | if (outgoingData) {
| 155-691 | ||||||||||||||||||
205 | // there is data to be uploaded, e.g. HTTP POST. | - | ||||||||||||||||||
206 | - | |||||||||||||||||||
207 | if (!d->outgoingData->isSequential()) {
| 59-96 | ||||||||||||||||||
208 | // fixed size non-sequential (random-access) | - | ||||||||||||||||||
209 | // just start the operation | - | ||||||||||||||||||
210 | QMetaObject::invokeMethod(this, "_q_startOperation", Qt::QueuedConnection); | - | ||||||||||||||||||
211 | // FIXME make direct call? | - | ||||||||||||||||||
212 | } else { executed 96 times by 3 tests: end of block Executed by:
| 96 | ||||||||||||||||||
213 | bool bufferingDisallowed = | - | ||||||||||||||||||
214 | request.attribute(QNetworkRequest::DoNotBufferUploadDataAttribute, | - | ||||||||||||||||||
215 | false).toBool(); | - | ||||||||||||||||||
216 | - | |||||||||||||||||||
217 | if (bufferingDisallowed) {
| 1-58 | ||||||||||||||||||
218 | // if a valid content-length header for the request was supplied, we can disable buffering | - | ||||||||||||||||||
219 | // if not, we will buffer anyway | - | ||||||||||||||||||
220 | if (request.header(QNetworkRequest::ContentLengthHeader).isValid()) {
| 0-1 | ||||||||||||||||||
221 | QMetaObject::invokeMethod(this, "_q_startOperation", Qt::QueuedConnection); | - | ||||||||||||||||||
222 | // FIXME make direct call? | - | ||||||||||||||||||
223 | } else { executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
224 | d->state = d->Buffering; | - | ||||||||||||||||||
225 | QMetaObject::invokeMethod(this, "_q_bufferOutgoingData", Qt::QueuedConnection); | - | ||||||||||||||||||
226 | } never executed: end of block | 0 | ||||||||||||||||||
227 | } else { | - | ||||||||||||||||||
228 | // _q_startOperation will be called when the buffering has finished. | - | ||||||||||||||||||
229 | d->state = d->Buffering; | - | ||||||||||||||||||
230 | QMetaObject::invokeMethod(this, "_q_bufferOutgoingData", Qt::QueuedConnection); | - | ||||||||||||||||||
231 | } executed 58 times by 1 test: end of block Executed by:
| 58 | ||||||||||||||||||
232 | } | - | ||||||||||||||||||
233 | } else { | - | ||||||||||||||||||
234 | // No outgoing data (POST, ..) | - | ||||||||||||||||||
235 | d->_q_startOperation(); | - | ||||||||||||||||||
236 | } executed 691 times by 7 tests: end of block Executed by:
| 691 | ||||||||||||||||||
237 | } | - | ||||||||||||||||||
238 | - | |||||||||||||||||||
239 | QNetworkReplyHttpImpl::~QNetworkReplyHttpImpl() | - | ||||||||||||||||||
240 | { | - | ||||||||||||||||||
241 | // This will do nothing if the request was already finished or aborted | - | ||||||||||||||||||
242 | emit abortHttpRequest(); | - | ||||||||||||||||||
243 | } executed 886 times by 9 tests: end of block Executed by:
| 886 | ||||||||||||||||||
244 | - | |||||||||||||||||||
245 | void QNetworkReplyHttpImpl::close() | - | ||||||||||||||||||
246 | { | - | ||||||||||||||||||
247 | Q_D(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
248 | - | |||||||||||||||||||
249 | if (d->state == QNetworkReplyPrivate::Aborted ||
| 0-1 | ||||||||||||||||||
250 | d->state == QNetworkReplyPrivate::Finished)
| 0-1 | ||||||||||||||||||
251 | return; never executed: return; | 0 | ||||||||||||||||||
252 | - | |||||||||||||||||||
253 | // According to the documentation close only stops the download | - | ||||||||||||||||||
254 | // by closing we can ignore the download part and continue uploading. | - | ||||||||||||||||||
255 | QNetworkReply::close(); | - | ||||||||||||||||||
256 | - | |||||||||||||||||||
257 | // call finished which will emit signals | - | ||||||||||||||||||
258 | // FIXME shouldn't this be emitted Queued? | - | ||||||||||||||||||
259 | d->error(OperationCanceledError, tr("Operation canceled")); | - | ||||||||||||||||||
260 | d->finished(); | - | ||||||||||||||||||
261 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
262 | - | |||||||||||||||||||
263 | void QNetworkReplyHttpImpl::abort() | - | ||||||||||||||||||
264 | { | - | ||||||||||||||||||
265 | Q_D(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
266 | // FIXME | - | ||||||||||||||||||
267 | if (d->state == QNetworkReplyPrivate::Finished || d->state == QNetworkReplyPrivate::Aborted)
| 0-2 | ||||||||||||||||||
268 | return; executed 1 time by 1 test: return; Executed by:
| 1 | ||||||||||||||||||
269 | - | |||||||||||||||||||
270 | QNetworkReply::close(); | - | ||||||||||||||||||
271 | - | |||||||||||||||||||
272 | if (d->state != QNetworkReplyPrivate::Finished) {
| 0-2 | ||||||||||||||||||
273 | // call finished which will emit signals | - | ||||||||||||||||||
274 | // FIXME shouldn't this be emitted Queued? | - | ||||||||||||||||||
275 | d->error(OperationCanceledError, tr("Operation canceled")); | - | ||||||||||||||||||
276 | - | |||||||||||||||||||
277 | // If state is WaitingForSession, calling finished has no effect | - | ||||||||||||||||||
278 | if (d->state == QNetworkReplyPrivate::WaitingForSession)
| 0-2 | ||||||||||||||||||
279 | d->state = QNetworkReplyPrivate::Working; never executed: d->state = QNetworkReplyPrivate::Working; | 0 | ||||||||||||||||||
280 | d->finished(); | - | ||||||||||||||||||
281 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
282 | - | |||||||||||||||||||
283 | d->state = QNetworkReplyPrivate::Aborted; | - | ||||||||||||||||||
284 | - | |||||||||||||||||||
285 | emit abortHttpRequest(); | - | ||||||||||||||||||
286 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
287 | - | |||||||||||||||||||
288 | qint64 QNetworkReplyHttpImpl::bytesAvailable() const | - | ||||||||||||||||||
289 | { | - | ||||||||||||||||||
290 | Q_D(const QNetworkReplyHttpImpl); | - | ||||||||||||||||||
291 | - | |||||||||||||||||||
292 | // if we load from cache device | - | ||||||||||||||||||
293 | if (d->cacheLoadDevice) {
| 0-1687 | ||||||||||||||||||
294 | return QNetworkReply::bytesAvailable() + d->cacheLoadDevice->bytesAvailable() + d->downloadMultiBuffer.byteAmount(); never executed: return QNetworkReply::bytesAvailable() + d->cacheLoadDevice->bytesAvailable() + d->downloadMultiBuffer.byteAmount(); | 0 | ||||||||||||||||||
295 | } | - | ||||||||||||||||||
296 | - | |||||||||||||||||||
297 | // zerocopy buffer | - | ||||||||||||||||||
298 | if (d->downloadZerocopyBuffer) {
| 486-1201 | ||||||||||||||||||
299 | return QNetworkReply::bytesAvailable() + d->downloadBufferCurrentSize - d->downloadBufferReadPosition; executed 1201 times by 1 test: return QNetworkReply::bytesAvailable() + d->downloadBufferCurrentSize - d->downloadBufferReadPosition; Executed by:
| 1201 | ||||||||||||||||||
300 | } | - | ||||||||||||||||||
301 | - | |||||||||||||||||||
302 | // normal buffer | - | ||||||||||||||||||
303 | return QNetworkReply::bytesAvailable() + d->downloadMultiBuffer.byteAmount(); executed 486 times by 1 test: return QNetworkReply::bytesAvailable() + d->downloadMultiBuffer.byteAmount(); Executed by:
| 486 | ||||||||||||||||||
304 | } | - | ||||||||||||||||||
305 | - | |||||||||||||||||||
306 | bool QNetworkReplyHttpImpl::isSequential () const | - | ||||||||||||||||||
307 | { | - | ||||||||||||||||||
308 | // FIXME In the cache of a cached load or the zero-copy buffer we could actually be non-sequential. | - | ||||||||||||||||||
309 | // FIXME however this requires us to implement stuff like seek() too. | - | ||||||||||||||||||
310 | return true; executed 574 times by 3 tests: return true; Executed by:
| 574 | ||||||||||||||||||
311 | } | - | ||||||||||||||||||
312 | - | |||||||||||||||||||
313 | qint64 QNetworkReplyHttpImpl::size() const | - | ||||||||||||||||||
314 | { | - | ||||||||||||||||||
315 | // FIXME At some point, this could return a proper value, e.g. if we're non-sequential. | - | ||||||||||||||||||
316 | return QNetworkReply::size(); executed 67 times by 1 test: return QNetworkReply::size(); Executed by:
| 67 | ||||||||||||||||||
317 | } | - | ||||||||||||||||||
318 | - | |||||||||||||||||||
319 | qint64 QNetworkReplyHttpImpl::readData(char* data, qint64 maxlen) | - | ||||||||||||||||||
320 | { | - | ||||||||||||||||||
321 | Q_D(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
322 | - | |||||||||||||||||||
323 | // cacheload device | - | ||||||||||||||||||
324 | if (d->cacheLoadDevice) {
| 0-1510 | ||||||||||||||||||
325 | // FIXME bytesdownloaded, position etc? | - | ||||||||||||||||||
326 | - | |||||||||||||||||||
327 | // There is something already in the buffer we buffered before because the user did not read() | - | ||||||||||||||||||
328 | // anything, so we read there first: | - | ||||||||||||||||||
329 | if (!d->downloadMultiBuffer.isEmpty()) {
| 0 | ||||||||||||||||||
330 | return d->downloadMultiBuffer.read(data, maxlen); never executed: return d->downloadMultiBuffer.read(data, maxlen); | 0 | ||||||||||||||||||
331 | } | - | ||||||||||||||||||
332 | - | |||||||||||||||||||
333 | qint64 ret = d->cacheLoadDevice->read(data, maxlen); | - | ||||||||||||||||||
334 | return ret; never executed: return ret; | 0 | ||||||||||||||||||
335 | } | - | ||||||||||||||||||
336 | - | |||||||||||||||||||
337 | // zerocopy buffer | - | ||||||||||||||||||
338 | if (d->downloadZerocopyBuffer) {
| 593-917 | ||||||||||||||||||
339 | // FIXME bytesdownloaded, position etc? | - | ||||||||||||||||||
340 | - | |||||||||||||||||||
341 | qint64 howMuch = qMin(maxlen, (d->downloadBufferCurrentSize - d->downloadBufferReadPosition)); | - | ||||||||||||||||||
342 | memcpy(data, d->downloadZerocopyBuffer + d->downloadBufferReadPosition, howMuch); | - | ||||||||||||||||||
343 | d->downloadBufferReadPosition += howMuch; | - | ||||||||||||||||||
344 | return howMuch; executed 593 times by 2 tests: return howMuch; Executed by:
| 593 | ||||||||||||||||||
345 | - | |||||||||||||||||||
346 | } | - | ||||||||||||||||||
347 | - | |||||||||||||||||||
348 | // normal buffer | - | ||||||||||||||||||
349 | if (d->downloadMultiBuffer.isEmpty()) {
| 395-522 | ||||||||||||||||||
350 | if (d->state == d->Finished || d->state == d->Aborted)
| 0-286 | ||||||||||||||||||
351 | return -1; executed 286 times by 3 tests: return -1; Executed by:
| 286 | ||||||||||||||||||
352 | return 0; executed 109 times by 1 test: return 0; Executed by:
| 109 | ||||||||||||||||||
353 | } | - | ||||||||||||||||||
354 | - | |||||||||||||||||||
355 | if (maxlen == 1) {
| 0-522 | ||||||||||||||||||
356 | // optimization for getChar() | - | ||||||||||||||||||
357 | *data = d->downloadMultiBuffer.getChar(); | - | ||||||||||||||||||
358 | if (readBufferSize())
| 0 | ||||||||||||||||||
359 | emit readBufferFreed(1); never executed: readBufferFreed(1); | 0 | ||||||||||||||||||
360 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
361 | } | - | ||||||||||||||||||
362 | - | |||||||||||||||||||
363 | maxlen = qMin<qint64>(maxlen, d->downloadMultiBuffer.byteAmount()); | - | ||||||||||||||||||
364 | qint64 bytesRead = d->downloadMultiBuffer.read(data, maxlen); | - | ||||||||||||||||||
365 | if (readBufferSize())
| 150-372 | ||||||||||||||||||
366 | emit readBufferFreed(bytesRead); executed 150 times by 1 test: readBufferFreed(bytesRead); Executed by:
| 150 | ||||||||||||||||||
367 | return bytesRead; executed 522 times by 3 tests: return bytesRead; Executed by:
| 522 | ||||||||||||||||||
368 | } | - | ||||||||||||||||||
369 | - | |||||||||||||||||||
370 | void QNetworkReplyHttpImpl::setReadBufferSize(qint64 size) | - | ||||||||||||||||||
371 | { | - | ||||||||||||||||||
372 | QNetworkReply::setReadBufferSize(size); | - | ||||||||||||||||||
373 | emit readBufferSizeChanged(size); | - | ||||||||||||||||||
374 | return; executed 18 times by 1 test: return; Executed by:
| 18 | ||||||||||||||||||
375 | } | - | ||||||||||||||||||
376 | - | |||||||||||||||||||
377 | bool QNetworkReplyHttpImpl::canReadLine () const | - | ||||||||||||||||||
378 | { | - | ||||||||||||||||||
379 | Q_D(const QNetworkReplyHttpImpl); | - | ||||||||||||||||||
380 | - | |||||||||||||||||||
381 | if (QNetworkReply::canReadLine())
| 1-5 | ||||||||||||||||||
382 | return true; executed 1 time by 1 test: return true; Executed by:
| 1 | ||||||||||||||||||
383 | - | |||||||||||||||||||
384 | if (d->cacheLoadDevice)
| 0-5 | ||||||||||||||||||
385 | return d->cacheLoadDevice->canReadLine() || d->downloadMultiBuffer.canReadLine(); never executed: return d->cacheLoadDevice->canReadLine() || d->downloadMultiBuffer.canReadLine();
| 0 | ||||||||||||||||||
386 | - | |||||||||||||||||||
387 | if (d->downloadZerocopyBuffer)
| 0-5 | ||||||||||||||||||
388 | return memchr(d->downloadZerocopyBuffer + d->downloadBufferReadPosition, '\n', d->downloadBufferCurrentSize - d->downloadBufferReadPosition); executed 5 times by 1 test: return memchr(d->downloadZerocopyBuffer + d->downloadBufferReadPosition, '\n', d->downloadBufferCurrentSize - d->downloadBufferReadPosition); Executed by:
| 5 | ||||||||||||||||||
389 | - | |||||||||||||||||||
390 | return d->downloadMultiBuffer.canReadLine(); never executed: return d->downloadMultiBuffer.canReadLine(); | 0 | ||||||||||||||||||
391 | } | - | ||||||||||||||||||
392 | - | |||||||||||||||||||
393 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
394 | void QNetworkReplyHttpImpl::ignoreSslErrors() | - | ||||||||||||||||||
395 | { | - | ||||||||||||||||||
396 | Q_D(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
397 | - | |||||||||||||||||||
398 | d->pendingIgnoreAllSslErrors = true; | - | ||||||||||||||||||
399 | } executed 143 times by 2 tests: end of block Executed by:
| 143 | ||||||||||||||||||
400 | - | |||||||||||||||||||
401 | void QNetworkReplyHttpImpl::ignoreSslErrorsImplementation(const QList<QSslError> &errors) | - | ||||||||||||||||||
402 | { | - | ||||||||||||||||||
403 | Q_D(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
404 | - | |||||||||||||||||||
405 | // the pending list is set if QNetworkReply::ignoreSslErrors(const QList<QSslError> &errors) | - | ||||||||||||||||||
406 | // is called before QNetworkAccessManager::get() (or post(), etc.) | - | ||||||||||||||||||
407 | d->pendingIgnoreSslErrorsList = errors; | - | ||||||||||||||||||
408 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||
409 | - | |||||||||||||||||||
410 | void QNetworkReplyHttpImpl::setSslConfigurationImplementation(const QSslConfiguration &newconfig) | - | ||||||||||||||||||
411 | { | - | ||||||||||||||||||
412 | // Setting a SSL configuration on a reply is not supported. The user needs to set | - | ||||||||||||||||||
413 | // her/his QSslConfiguration on the QNetworkRequest. | - | ||||||||||||||||||
414 | Q_UNUSED(newconfig); | - | ||||||||||||||||||
415 | } never executed: end of block | 0 | ||||||||||||||||||
416 | - | |||||||||||||||||||
417 | void QNetworkReplyHttpImpl::sslConfigurationImplementation(QSslConfiguration &configuration) const | - | ||||||||||||||||||
418 | { | - | ||||||||||||||||||
419 | Q_D(const QNetworkReplyHttpImpl); | - | ||||||||||||||||||
420 | configuration = d->sslConfiguration; | - | ||||||||||||||||||
421 | } executed 211 times by 2 tests: end of block Executed by:
| 211 | ||||||||||||||||||
422 | #endif | - | ||||||||||||||||||
423 | - | |||||||||||||||||||
424 | QNetworkReplyHttpImplPrivate::QNetworkReplyHttpImplPrivate() | - | ||||||||||||||||||
425 | : QNetworkReplyPrivate() | - | ||||||||||||||||||
426 | , manager(0) | - | ||||||||||||||||||
427 | , managerPrivate(0) | - | ||||||||||||||||||
428 | , synchronous(false) | - | ||||||||||||||||||
429 | , state(Idle) | - | ||||||||||||||||||
430 | , statusCode(0) | - | ||||||||||||||||||
431 | , uploadByteDevicePosition(false) | - | ||||||||||||||||||
432 | , uploadDeviceChoking(false) | - | ||||||||||||||||||
433 | , outgoingData(0) | - | ||||||||||||||||||
434 | , bytesUploaded(-1) | - | ||||||||||||||||||
435 | , cacheLoadDevice(0) | - | ||||||||||||||||||
436 | , loadingFromCache(false) | - | ||||||||||||||||||
437 | , cacheSaveDevice(0) | - | ||||||||||||||||||
438 | , cacheEnabled(false) | - | ||||||||||||||||||
439 | , resumeOffset(0) | - | ||||||||||||||||||
440 | , preMigrationDownloaded(-1) | - | ||||||||||||||||||
441 | , bytesDownloaded(0) | - | ||||||||||||||||||
442 | , downloadBufferReadPosition(0) | - | ||||||||||||||||||
443 | , downloadBufferCurrentSize(0) | - | ||||||||||||||||||
444 | , downloadZerocopyBuffer(0) | - | ||||||||||||||||||
445 | , pendingDownloadDataEmissions(QSharedPointer<QAtomicInt>::create()) | - | ||||||||||||||||||
446 | , pendingDownloadProgressEmissions(QSharedPointer<QAtomicInt>::create()) | - | ||||||||||||||||||
447 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
448 | , pendingIgnoreAllSslErrors(false) | - | ||||||||||||||||||
449 | #endif | - | ||||||||||||||||||
450 | - | |||||||||||||||||||
451 | { | - | ||||||||||||||||||
452 | } executed 887 times by 8 tests: end of block Executed by:
| 887 | ||||||||||||||||||
453 | - | |||||||||||||||||||
454 | QNetworkReplyHttpImplPrivate::~QNetworkReplyHttpImplPrivate() | - | ||||||||||||||||||
455 | { | - | ||||||||||||||||||
456 | } | - | ||||||||||||||||||
457 | - | |||||||||||||||||||
458 | /* | - | ||||||||||||||||||
459 | For a given httpRequest | - | ||||||||||||||||||
460 | 1) If AlwaysNetwork, return | - | ||||||||||||||||||
461 | 2) If we have a cache entry for this url populate headers so the server can return 304 | - | ||||||||||||||||||
462 | 3) Calculate if response_is_fresh and if so send the cache and set loadedFromCache to true | - | ||||||||||||||||||
463 | */ | - | ||||||||||||||||||
464 | bool QNetworkReplyHttpImplPrivate::loadFromCacheIfAllowed(QHttpNetworkRequest &httpRequest) | - | ||||||||||||||||||
465 | { | - | ||||||||||||||||||
466 | QNetworkRequest::CacheLoadControl CacheLoadControlAttribute = | - | ||||||||||||||||||
467 | (QNetworkRequest::CacheLoadControl)request.attribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork).toInt(); | - | ||||||||||||||||||
468 | if (CacheLoadControlAttribute == QNetworkRequest::AlwaysNetwork) {
| 12-668 | ||||||||||||||||||
469 | // If the request does not already specify preferred cache-control | - | ||||||||||||||||||
470 | // force reload from the network and tell any caching proxy servers to reload too | - | ||||||||||||||||||
471 | if (!request.rawHeaderList().contains("Cache-Control")) {
| 0-12 | ||||||||||||||||||
472 | httpRequest.setHeaderField("Cache-Control", "no-cache"); | - | ||||||||||||||||||
473 | httpRequest.setHeaderField("Pragma", "no-cache"); | - | ||||||||||||||||||
474 | } executed 12 times by 2 tests: end of block Executed by:
| 12 | ||||||||||||||||||
475 | return false; executed 12 times by 2 tests: return false; Executed by:
| 12 | ||||||||||||||||||
476 | } | - | ||||||||||||||||||
477 | - | |||||||||||||||||||
478 | // The disk cache API does not currently support partial content retrieval. | - | ||||||||||||||||||
479 | // That is why we don't use the disk cache for any such requests. | - | ||||||||||||||||||
480 | if (request.hasRawHeader("Range"))
| 2-666 | ||||||||||||||||||
481 | return false; executed 2 times by 1 test: return false; Executed by:
| 2 | ||||||||||||||||||
482 | - | |||||||||||||||||||
483 | QAbstractNetworkCache *nc = managerPrivate->networkCache; | - | ||||||||||||||||||
484 | if (!nc)
| 87-579 | ||||||||||||||||||
485 | return false; // no local cache executed 579 times by 6 tests: return false; Executed by:
| 579 | ||||||||||||||||||
486 | - | |||||||||||||||||||
487 | QNetworkCacheMetaData metaData = nc->metaData(httpRequest.url()); | - | ||||||||||||||||||
488 | if (!metaData.isValid())
| 37-50 | ||||||||||||||||||
489 | return false; // not in cache executed 50 times by 3 tests: return false; Executed by:
| 50 | ||||||||||||||||||
490 | - | |||||||||||||||||||
491 | if (!metaData.saveToDisk())
| 0-37 | ||||||||||||||||||
492 | return false; never executed: return false; | 0 | ||||||||||||||||||
493 | - | |||||||||||||||||||
494 | QNetworkHeadersPrivate cacheHeaders; | - | ||||||||||||||||||
495 | QNetworkHeadersPrivate::RawHeadersList::ConstIterator it; | - | ||||||||||||||||||
496 | cacheHeaders.setAllRawHeaders(metaData.rawHeaders()); | - | ||||||||||||||||||
497 | - | |||||||||||||||||||
498 | it = cacheHeaders.findRawHeader("etag"); | - | ||||||||||||||||||
499 | if (it != cacheHeaders.rawHeaders.constEnd())
| 4-33 | ||||||||||||||||||
500 | httpRequest.setHeaderField("If-None-Match", it->second); executed 4 times by 1 test: httpRequest.setHeaderField("If-None-Match", it->second); Executed by:
| 4 | ||||||||||||||||||
501 | - | |||||||||||||||||||
502 | QDateTime lastModified = metaData.lastModified(); | - | ||||||||||||||||||
503 | if (lastModified.isValid())
| 15-22 | ||||||||||||||||||
504 | httpRequest.setHeaderField("If-Modified-Since", QNetworkHeadersPrivate::toHttpDate(lastModified)); executed 22 times by 2 tests: httpRequest.setHeaderField("If-Modified-Since", QNetworkHeadersPrivate::toHttpDate(lastModified)); Executed by:
| 22 | ||||||||||||||||||
505 | - | |||||||||||||||||||
506 | it = cacheHeaders.findRawHeader("Cache-Control"); | - | ||||||||||||||||||
507 | if (it != cacheHeaders.rawHeaders.constEnd()) {
| 15-22 | ||||||||||||||||||
508 | QHash<QByteArray, QByteArray> cacheControl = parseHttpOptionHeader(it->second); | - | ||||||||||||||||||
509 | if (cacheControl.contains("must-revalidate"))
| 6-16 | ||||||||||||||||||
510 | return false; executed 6 times by 2 tests: return false; Executed by:
| 6 | ||||||||||||||||||
511 | } executed 16 times by 2 tests: end of block Executed by:
| 16 | ||||||||||||||||||
512 | - | |||||||||||||||||||
513 | QDateTime currentDateTime = QDateTime::currentDateTimeUtc(); | - | ||||||||||||||||||
514 | QDateTime expirationDate = metaData.expirationDate(); | - | ||||||||||||||||||
515 | - | |||||||||||||||||||
516 | bool response_is_fresh; | - | ||||||||||||||||||
517 | if (!expirationDate.isValid()) {
| 9-22 | ||||||||||||||||||
518 | /* | - | ||||||||||||||||||
519 | * age_value | - | ||||||||||||||||||
520 | * is the value of Age: header received by the cache with | - | ||||||||||||||||||
521 | * this response. | - | ||||||||||||||||||
522 | * date_value | - | ||||||||||||||||||
523 | * is the value of the origin server's Date: header | - | ||||||||||||||||||
524 | * request_time | - | ||||||||||||||||||
525 | * is the (local) time when the cache made the request | - | ||||||||||||||||||
526 | * that resulted in this cached response | - | ||||||||||||||||||
527 | * response_time | - | ||||||||||||||||||
528 | * is the (local) time when the cache received the | - | ||||||||||||||||||
529 | * response | - | ||||||||||||||||||
530 | * now | - | ||||||||||||||||||
531 | * is the current (local) time | - | ||||||||||||||||||
532 | */ | - | ||||||||||||||||||
533 | int age_value = 0; | - | ||||||||||||||||||
534 | it = cacheHeaders.findRawHeader("age"); | - | ||||||||||||||||||
535 | if (it != cacheHeaders.rawHeaders.constEnd())
| 0-9 | ||||||||||||||||||
536 | age_value = it->second.toInt(); never executed: age_value = it->second.toInt(); | 0 | ||||||||||||||||||
537 | - | |||||||||||||||||||
538 | QDateTime dateHeader; | - | ||||||||||||||||||
539 | int date_value = 0; | - | ||||||||||||||||||
540 | it = cacheHeaders.findRawHeader("date"); | - | ||||||||||||||||||
541 | if (it != cacheHeaders.rawHeaders.constEnd()) {
| 1-8 | ||||||||||||||||||
542 | dateHeader = QNetworkHeadersPrivate::fromHttpDate(it->second); | - | ||||||||||||||||||
543 | date_value = dateHeader.toTime_t(); | - | ||||||||||||||||||
544 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
545 | - | |||||||||||||||||||
546 | int now = currentDateTime.toTime_t(); | - | ||||||||||||||||||
547 | int request_time = now; | - | ||||||||||||||||||
548 | int response_time = now; | - | ||||||||||||||||||
549 | - | |||||||||||||||||||
550 | // Algorithm from RFC 2616 section 13.2.3 | - | ||||||||||||||||||
551 | int apparent_age = qMax(0, response_time - date_value); | - | ||||||||||||||||||
552 | int corrected_received_age = qMax(apparent_age, age_value); | - | ||||||||||||||||||
553 | int response_delay = response_time - request_time; | - | ||||||||||||||||||
554 | int corrected_initial_age = corrected_received_age + response_delay; | - | ||||||||||||||||||
555 | int resident_time = now - response_time; | - | ||||||||||||||||||
556 | int current_age = corrected_initial_age + resident_time; | - | ||||||||||||||||||
557 | - | |||||||||||||||||||
558 | int freshness_lifetime = 0; | - | ||||||||||||||||||
559 | - | |||||||||||||||||||
560 | // RFC 2616 13.2.4 Expiration Calculations | - | ||||||||||||||||||
561 | if (lastModified.isValid() && dateHeader.isValid()) {
| 0-5 | ||||||||||||||||||
562 | int diff = lastModified.secsTo(dateHeader); | - | ||||||||||||||||||
563 | freshness_lifetime = diff / 10; | - | ||||||||||||||||||
564 | if (httpRequest.headerField("Warning").isEmpty()) {
| 0-4 | ||||||||||||||||||
565 | QDateTime dt = currentDateTime.addSecs(current_age); | - | ||||||||||||||||||
566 | if (currentDateTime.daysTo(dt) > 1)
| 0-4 | ||||||||||||||||||
567 | httpRequest.setHeaderField("Warning", "113"); never executed: httpRequest.setHeaderField("Warning", "113"); | 0 | ||||||||||||||||||
568 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
569 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
570 | - | |||||||||||||||||||
571 | // the cache-saving code below sets the freshness_lifetime with (dateHeader - last_modified) / 10 | - | ||||||||||||||||||
572 | // if "last-modified" is present, or to Expires otherwise | - | ||||||||||||||||||
573 | response_is_fresh = (freshness_lifetime > current_age); | - | ||||||||||||||||||
574 | } else { executed 9 times by 2 tests: end of block Executed by:
| 9 | ||||||||||||||||||
575 | // expiration date was calculated earlier (e.g. when storing object to the cache) | - | ||||||||||||||||||
576 | response_is_fresh = currentDateTime.secsTo(expirationDate) >= 0; | - | ||||||||||||||||||
577 | } executed 22 times by 2 tests: end of block Executed by:
| 22 | ||||||||||||||||||
578 | - | |||||||||||||||||||
579 | if (!response_is_fresh)
| 13-18 | ||||||||||||||||||
580 | return false; executed 13 times by 3 tests: return false; Executed by:
| 13 | ||||||||||||||||||
581 | - | |||||||||||||||||||
582 | #if defined(QNETWORKACCESSHTTPBACKEND_DEBUG) | - | ||||||||||||||||||
583 | qDebug() << "response_is_fresh" << CacheLoadControlAttribute; | - | ||||||||||||||||||
584 | #endif | - | ||||||||||||||||||
585 | return sendCacheContents(metaData); executed 18 times by 2 tests: return sendCacheContents(metaData); Executed by:
| 18 | ||||||||||||||||||
586 | } | - | ||||||||||||||||||
587 | - | |||||||||||||||||||
588 | QHttpNetworkRequest::Priority QNetworkReplyHttpImplPrivate::convert(const QNetworkRequest::Priority& prio) | - | ||||||||||||||||||
589 | { | - | ||||||||||||||||||
590 | switch (prio) { | - | ||||||||||||||||||
591 | case QNetworkRequest::LowPriority: never executed: case QNetworkRequest::LowPriority: | 0 | ||||||||||||||||||
592 | return QHttpNetworkRequest::LowPriority; never executed: return QHttpNetworkRequest::LowPriority; | 0 | ||||||||||||||||||
593 | case QNetworkRequest::HighPriority: never executed: case QNetworkRequest::HighPriority: | 0 | ||||||||||||||||||
594 | return QHttpNetworkRequest::HighPriority; never executed: return QHttpNetworkRequest::HighPriority; | 0 | ||||||||||||||||||
595 | case QNetworkRequest::NormalPriority: executed 887 times by 8 tests: case QNetworkRequest::NormalPriority: Executed by:
| 887 | ||||||||||||||||||
596 | default: never executed: default: | 0 | ||||||||||||||||||
597 | return QHttpNetworkRequest::NormalPriority; executed 887 times by 8 tests: return QHttpNetworkRequest::NormalPriority; Executed by:
| 887 | ||||||||||||||||||
598 | } | - | ||||||||||||||||||
599 | } | - | ||||||||||||||||||
600 | - | |||||||||||||||||||
601 | void QNetworkReplyHttpImplPrivate::postRequest(const QNetworkRequest &newHttpRequest) | - | ||||||||||||||||||
602 | { | - | ||||||||||||||||||
603 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
604 | - | |||||||||||||||||||
605 | QThread *thread = 0; | - | ||||||||||||||||||
606 | if (synchronous) {
| 76-814 | ||||||||||||||||||
607 | // A synchronous HTTP request uses its own thread | - | ||||||||||||||||||
608 | thread = new QThread(); | - | ||||||||||||||||||
609 | thread->setObjectName(QStringLiteral("Qt HTTP synchronous thread")); executed 76 times by 1 test: return qstring_literal_temp; Executed by:
| 76 | ||||||||||||||||||
610 | QObject::connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); | - | ||||||||||||||||||
611 | thread->start(); | - | ||||||||||||||||||
612 | } else if (!managerPrivate->httpThread) { executed 76 times by 1 test: end of block Executed by:
| 76-471 | ||||||||||||||||||
613 | // We use the manager-global thread. | - | ||||||||||||||||||
614 | // At some point we could switch to having multiple threads if it makes sense. | - | ||||||||||||||||||
615 | managerPrivate->httpThread = new QThread(); | - | ||||||||||||||||||
616 | managerPrivate->httpThread->setObjectName(QStringLiteral("Qt HTTP thread")); executed 471 times by 8 tests: return qstring_literal_temp; Executed by:
| 471 | ||||||||||||||||||
617 | managerPrivate->httpThread->start(); | - | ||||||||||||||||||
618 | - | |||||||||||||||||||
619 | thread = managerPrivate->httpThread; | - | ||||||||||||||||||
620 | } else { executed 471 times by 8 tests: end of block Executed by:
| 471 | ||||||||||||||||||
621 | // Asynchronous request, thread already exists | - | ||||||||||||||||||
622 | thread = managerPrivate->httpThread; | - | ||||||||||||||||||
623 | } executed 343 times by 4 tests: end of block Executed by:
| 343 | ||||||||||||||||||
624 | - | |||||||||||||||||||
625 | QUrl url = newHttpRequest.url(); | - | ||||||||||||||||||
626 | httpRequest.setUrl(url); | - | ||||||||||||||||||
627 | httpRequest.setRedirectCount(newHttpRequest.maximumRedirectsAllowed()); | - | ||||||||||||||||||
628 | - | |||||||||||||||||||
629 | QString scheme = url.scheme(); | - | ||||||||||||||||||
630 | bool ssl = (scheme == QLatin1String("https")
| 231-659 | ||||||||||||||||||
631 | || scheme == QLatin1String("preconnect-https"));
| 0-659 | ||||||||||||||||||
632 | q->setAttribute(QNetworkRequest::ConnectionEncryptedAttribute, ssl); | - | ||||||||||||||||||
633 | httpRequest.setSsl(ssl); | - | ||||||||||||||||||
634 | - | |||||||||||||||||||
635 | bool preConnect = (scheme == QLatin1String("preconnect-http")
| 0-890 | ||||||||||||||||||
636 | || scheme == QLatin1String("preconnect-https"));
| 0-890 | ||||||||||||||||||
637 | httpRequest.setPreConnect(preConnect); | - | ||||||||||||||||||
638 | - | |||||||||||||||||||
639 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
640 | QNetworkProxy transparentProxy, cacheProxy; | - | ||||||||||||||||||
641 | - | |||||||||||||||||||
642 | // FIXME the proxy stuff should be done in the HTTP thread | - | ||||||||||||||||||
643 | foreach (const QNetworkProxy &p, managerPrivate->queryProxy(QNetworkProxyQuery(newHttpRequest.url()))) { | - | ||||||||||||||||||
644 | // use the first proxy that works | - | ||||||||||||||||||
645 | // for non-encrypted connections, any transparent or HTTP proxy | - | ||||||||||||||||||
646 | // for encrypted, only transparent proxies | - | ||||||||||||||||||
647 | if (!ssl
| 234-661 | ||||||||||||||||||
648 | && (p.capabilities() & QNetworkProxy::CachingCapability) | - | ||||||||||||||||||
649 | && (p.type() == QNetworkProxy::HttpProxy ||
| 11-47 | ||||||||||||||||||
650 | p.type() == QNetworkProxy::HttpCachingProxy)) {
| 3-8 | ||||||||||||||||||
651 | cacheProxy = p; | - | ||||||||||||||||||
652 | transparentProxy = QNetworkProxy::NoProxy; | - | ||||||||||||||||||
653 | break; executed 55 times by 1 test: break; Executed by:
| 55 | ||||||||||||||||||
654 | } | - | ||||||||||||||||||
655 | if (p.isTransparentProxy()) {
| 8-832 | ||||||||||||||||||
656 | transparentProxy = p; | - | ||||||||||||||||||
657 | cacheProxy = QNetworkProxy::NoProxy; | - | ||||||||||||||||||
658 | break; executed 832 times by 8 tests: break; Executed by:
| 832 | ||||||||||||||||||
659 | } | - | ||||||||||||||||||
660 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
661 | - | |||||||||||||||||||
662 | // check if at least one of the proxies | - | ||||||||||||||||||
663 | if (transparentProxy.type() == QNetworkProxy::DefaultProxy &&
| 3-887 | ||||||||||||||||||
664 | cacheProxy.type() == QNetworkProxy::DefaultProxy) {
| 0-3 | ||||||||||||||||||
665 | // unsuitable proxies | - | ||||||||||||||||||
666 | QMetaObject::invokeMethod(q, "_q_error", synchronous ? Qt::DirectConnection : Qt::QueuedConnection, | - | ||||||||||||||||||
667 | Q_ARG(QNetworkReply::NetworkError, QNetworkReply::ProxyNotFoundError), | - | ||||||||||||||||||
668 | Q_ARG(QString, QNetworkReplyHttpImpl::tr("No suitable proxy found"))); | - | ||||||||||||||||||
669 | QMetaObject::invokeMethod(q, "_q_finished", synchronous ? Qt::DirectConnection : Qt::QueuedConnection); | - | ||||||||||||||||||
670 | return; executed 3 times by 1 test: return; Executed by:
| 3 | ||||||||||||||||||
671 | } | - | ||||||||||||||||||
672 | #endif | - | ||||||||||||||||||
673 | - | |||||||||||||||||||
674 | if (newHttpRequest.attribute(QNetworkRequest::FollowRedirectsAttribute).toBool())
| 9-878 | ||||||||||||||||||
675 | httpRequest.setFollowRedirects(true); executed 9 times by 1 test: httpRequest.setFollowRedirects(true); Executed by:
| 9 | ||||||||||||||||||
676 | - | |||||||||||||||||||
677 | httpRequest.setPriority(convert(newHttpRequest.priority())); | - | ||||||||||||||||||
678 | - | |||||||||||||||||||
679 | switch (operation) { | - | ||||||||||||||||||
680 | case QNetworkAccessManager::GetOperation: executed 654 times by 7 tests: case QNetworkAccessManager::GetOperation: Executed by:
| 654 | ||||||||||||||||||
681 | httpRequest.setOperation(QHttpNetworkRequest::Get); | - | ||||||||||||||||||
682 | if (loadFromCacheIfAllowed(httpRequest))
| 18-636 | ||||||||||||||||||
683 | return; // no need to send the request! :) executed 18 times by 2 tests: return; Executed by:
| 18 | ||||||||||||||||||
684 | break; executed 636 times by 7 tests: break; Executed by:
| 636 | ||||||||||||||||||
685 | - | |||||||||||||||||||
686 | case QNetworkAccessManager::HeadOperation: executed 26 times by 1 test: case QNetworkAccessManager::HeadOperation: Executed by:
| 26 | ||||||||||||||||||
687 | httpRequest.setOperation(QHttpNetworkRequest::Head); | - | ||||||||||||||||||
688 | if (loadFromCacheIfAllowed(httpRequest))
| 0-26 | ||||||||||||||||||
689 | return; // no need to send the request! :) never executed: return; | 0 | ||||||||||||||||||
690 | break; executed 26 times by 1 test: break; Executed by:
| 26 | ||||||||||||||||||
691 | - | |||||||||||||||||||
692 | case QNetworkAccessManager::PostOperation: executed 157 times by 3 tests: case QNetworkAccessManager::PostOperation: Executed by:
| 157 | ||||||||||||||||||
693 | invalidateCache(); | - | ||||||||||||||||||
694 | httpRequest.setOperation(QHttpNetworkRequest::Post); | - | ||||||||||||||||||
695 | createUploadByteDevice(); | - | ||||||||||||||||||
696 | break; executed 157 times by 3 tests: break; Executed by:
| 157 | ||||||||||||||||||
697 | - | |||||||||||||||||||
698 | case QNetworkAccessManager::PutOperation: executed 36 times by 2 tests: case QNetworkAccessManager::PutOperation: Executed by:
| 36 | ||||||||||||||||||
699 | invalidateCache(); | - | ||||||||||||||||||
700 | httpRequest.setOperation(QHttpNetworkRequest::Put); | - | ||||||||||||||||||
701 | createUploadByteDevice(); | - | ||||||||||||||||||
702 | break; executed 36 times by 2 tests: break; Executed by:
| 36 | ||||||||||||||||||
703 | - | |||||||||||||||||||
704 | case QNetworkAccessManager::DeleteOperation: executed 7 times by 1 test: case QNetworkAccessManager::DeleteOperation: Executed by:
| 7 | ||||||||||||||||||
705 | invalidateCache(); | - | ||||||||||||||||||
706 | httpRequest.setOperation(QHttpNetworkRequest::Delete); | - | ||||||||||||||||||
707 | break; executed 7 times by 1 test: break; Executed by:
| 7 | ||||||||||||||||||
708 | - | |||||||||||||||||||
709 | case QNetworkAccessManager::CustomOperation: executed 7 times by 1 test: case QNetworkAccessManager::CustomOperation: Executed by:
| 7 | ||||||||||||||||||
710 | invalidateCache(); // for safety reasons, we don't know what the operation does | - | ||||||||||||||||||
711 | httpRequest.setOperation(QHttpNetworkRequest::Custom); | - | ||||||||||||||||||
712 | createUploadByteDevice(); | - | ||||||||||||||||||
713 | httpRequest.setCustomVerb(newHttpRequest.attribute( | - | ||||||||||||||||||
714 | QNetworkRequest::CustomVerbAttribute).toByteArray()); | - | ||||||||||||||||||
715 | break; executed 7 times by 1 test: break; Executed by:
| 7 | ||||||||||||||||||
716 | - | |||||||||||||||||||
717 | default: never executed: default: | 0 | ||||||||||||||||||
718 | break; // can't happen never executed: break; | 0 | ||||||||||||||||||
719 | } | - | ||||||||||||||||||
720 | - | |||||||||||||||||||
721 | QList<QByteArray> headers = newHttpRequest.rawHeaderList(); | - | ||||||||||||||||||
722 | if (resumeOffset != 0) {
| 0-869 | ||||||||||||||||||
723 | if (headers.contains("Range")) {
| 0 | ||||||||||||||||||
724 | // Need to adjust resume offset for user specified range | - | ||||||||||||||||||
725 | - | |||||||||||||||||||
726 | headers.removeOne("Range"); | - | ||||||||||||||||||
727 | - | |||||||||||||||||||
728 | // We've already verified that requestRange starts with "bytes=", see canResume. | - | ||||||||||||||||||
729 | QByteArray requestRange = newHttpRequest.rawHeader("Range").mid(6); | - | ||||||||||||||||||
730 | - | |||||||||||||||||||
731 | int index = requestRange.indexOf('-'); | - | ||||||||||||||||||
732 | - | |||||||||||||||||||
733 | quint64 requestStartOffset = requestRange.left(index).toULongLong(); | - | ||||||||||||||||||
734 | quint64 requestEndOffset = requestRange.mid(index + 1).toULongLong(); | - | ||||||||||||||||||
735 | - | |||||||||||||||||||
736 | requestRange = "bytes=" + QByteArray::number(resumeOffset + requestStartOffset) + | - | ||||||||||||||||||
737 | '-' + QByteArray::number(requestEndOffset); | - | ||||||||||||||||||
738 | - | |||||||||||||||||||
739 | httpRequest.setHeaderField("Range", requestRange); | - | ||||||||||||||||||
740 | } else { never executed: end of block | 0 | ||||||||||||||||||
741 | httpRequest.setHeaderField("Range", "bytes=" + QByteArray::number(resumeOffset) + '-'); | - | ||||||||||||||||||
742 | } never executed: end of block | 0 | ||||||||||||||||||
743 | } | - | ||||||||||||||||||
744 | - | |||||||||||||||||||
745 | foreach (const QByteArray &header, headers) | - | ||||||||||||||||||
746 | httpRequest.setHeaderField(header, newHttpRequest.rawHeader(header)); executed 319 times by 3 tests: httpRequest.setHeaderField(header, newHttpRequest.rawHeader(header)); Executed by:
| 319 | ||||||||||||||||||
747 | - | |||||||||||||||||||
748 | if (newHttpRequest.attribute(QNetworkRequest::HttpPipeliningAllowedAttribute).toBool())
| 20-849 | ||||||||||||||||||
749 | httpRequest.setPipeliningAllowed(true); executed 20 times by 1 test: httpRequest.setPipeliningAllowed(true); Executed by:
| 20 | ||||||||||||||||||
750 | - | |||||||||||||||||||
751 | if (request.attribute(QNetworkRequest::SpdyAllowedAttribute).toBool())
| 113-756 | ||||||||||||||||||
752 | httpRequest.setSPDYAllowed(true); executed 113 times by 1 test: httpRequest.setSPDYAllowed(true); Executed by:
| 113 | ||||||||||||||||||
753 | - | |||||||||||||||||||
754 | if (static_cast<QNetworkRequest::LoadControl>
| 1-868 | ||||||||||||||||||
755 | (newHttpRequest.attribute(QNetworkRequest::AuthenticationReuseAttribute,
| 1-868 | ||||||||||||||||||
756 | QNetworkRequest::Automatic).toInt()) == QNetworkRequest::Manual)
| 1-868 | ||||||||||||||||||
757 | httpRequest.setWithCredentials(false); executed 1 time by 1 test: httpRequest.setWithCredentials(false); Executed by:
| 1 | ||||||||||||||||||
758 | - | |||||||||||||||||||
759 | if (request.attribute(QNetworkRequest::EmitAllUploadProgressSignalsAttribute).toBool())
| 1-868 | ||||||||||||||||||
760 | emitAllUploadProgressSignals = true; executed 1 time by 1 test: emitAllUploadProgressSignals = true; Executed by:
| 1 | ||||||||||||||||||
761 | - | |||||||||||||||||||
762 | - | |||||||||||||||||||
763 | // Create the HTTP thread delegate | - | ||||||||||||||||||
764 | QHttpThreadDelegate *delegate = new QHttpThreadDelegate; | - | ||||||||||||||||||
765 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
766 | delegate->networkSession = managerPrivate->getNetworkSession(); | - | ||||||||||||||||||
767 | #endif | - | ||||||||||||||||||
768 | - | |||||||||||||||||||
769 | // For the synchronous HTTP, this is the normal way the delegate gets deleted | - | ||||||||||||||||||
770 | // For the asynchronous HTTP this is a safety measure, the delegate deletes itself when HTTP is finished | - | ||||||||||||||||||
771 | QObject::connect(thread, SIGNAL(finished()), delegate, SLOT(deleteLater())); | - | ||||||||||||||||||
772 | - | |||||||||||||||||||
773 | // Set the properties it needs | - | ||||||||||||||||||
774 | delegate->httpRequest = httpRequest; | - | ||||||||||||||||||
775 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
776 | delegate->cacheProxy = cacheProxy; | - | ||||||||||||||||||
777 | delegate->transparentProxy = transparentProxy; | - | ||||||||||||||||||
778 | #endif | - | ||||||||||||||||||
779 | delegate->ssl = ssl; | - | ||||||||||||||||||
780 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
781 | if (ssl)
| 229-640 | ||||||||||||||||||
782 | delegate->incomingSslConfiguration = newHttpRequest.sslConfiguration(); executed 229 times by 2 tests: delegate->incomingSslConfiguration = newHttpRequest.sslConfiguration(); Executed by:
| 229 | ||||||||||||||||||
783 | #endif | - | ||||||||||||||||||
784 | - | |||||||||||||||||||
785 | // Do we use synchronous HTTP? | - | ||||||||||||||||||
786 | delegate->synchronous = synchronous; | - | ||||||||||||||||||
787 | - | |||||||||||||||||||
788 | // The authentication manager is used to avoid the BlockingQueuedConnection communication | - | ||||||||||||||||||
789 | // from HTTP thread to user thread in some cases. | - | ||||||||||||||||||
790 | delegate->authenticationManager = managerPrivate->authenticationManager; | - | ||||||||||||||||||
791 | - | |||||||||||||||||||
792 | if (!synchronous) {
| 76-793 | ||||||||||||||||||
793 | // Tell our zerocopy policy to the delegate | - | ||||||||||||||||||
794 | QVariant downloadBufferMaximumSizeAttribute = newHttpRequest.attribute(QNetworkRequest::MaximumDownloadBufferSizeAttribute); | - | ||||||||||||||||||
795 | if (downloadBufferMaximumSizeAttribute.isValid()) {
| 7-786 | ||||||||||||||||||
796 | delegate->downloadBufferMaximumSize = downloadBufferMaximumSizeAttribute.toLongLong(); | - | ||||||||||||||||||
797 | } else { executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||
798 | // If there is no MaximumDownloadBufferSizeAttribute set (which is for the majority | - | ||||||||||||||||||
799 | // of QNetworkRequest) then we can assume we'll do it anyway for small HTTP replies. | - | ||||||||||||||||||
800 | // This helps with performance and memory fragmentation. | - | ||||||||||||||||||
801 | delegate->downloadBufferMaximumSize = 128*1024; | - | ||||||||||||||||||
802 | } executed 786 times by 8 tests: end of block Executed by:
| 786 | ||||||||||||||||||
803 | - | |||||||||||||||||||
804 | - | |||||||||||||||||||
805 | // These atomic integers are used for signal compression | - | ||||||||||||||||||
806 | delegate->pendingDownloadData = pendingDownloadDataEmissions; | - | ||||||||||||||||||
807 | delegate->pendingDownloadProgress = pendingDownloadProgressEmissions; | - | ||||||||||||||||||
808 | - | |||||||||||||||||||
809 | // Connect the signals of the delegate to us | - | ||||||||||||||||||
810 | QObject::connect(delegate, SIGNAL(downloadData(QByteArray)), | - | ||||||||||||||||||
811 | q, SLOT(replyDownloadData(QByteArray)), | - | ||||||||||||||||||
812 | Qt::QueuedConnection); | - | ||||||||||||||||||
813 | QObject::connect(delegate, SIGNAL(downloadFinished()), | - | ||||||||||||||||||
814 | q, SLOT(replyFinished()), | - | ||||||||||||||||||
815 | Qt::QueuedConnection); | - | ||||||||||||||||||
816 | QObject::connect(delegate, SIGNAL(downloadMetaData(QList<QPair<QByteArray,QByteArray> >, | - | ||||||||||||||||||
817 | int, QString, bool, | - | ||||||||||||||||||
818 | QSharedPointer<char>, qint64, bool)), | - | ||||||||||||||||||
819 | q, SLOT(replyDownloadMetaData(QList<QPair<QByteArray,QByteArray> >, | - | ||||||||||||||||||
820 | int, QString, bool, | - | ||||||||||||||||||
821 | QSharedPointer<char>, qint64, bool)), | - | ||||||||||||||||||
822 | Qt::QueuedConnection); | - | ||||||||||||||||||
823 | QObject::connect(delegate, SIGNAL(downloadProgress(qint64,qint64)), | - | ||||||||||||||||||
824 | q, SLOT(replyDownloadProgressSlot(qint64,qint64)), | - | ||||||||||||||||||
825 | Qt::QueuedConnection); | - | ||||||||||||||||||
826 | QObject::connect(delegate, SIGNAL(error(QNetworkReply::NetworkError,QString)), | - | ||||||||||||||||||
827 | q, SLOT(httpError(QNetworkReply::NetworkError,QString)), | - | ||||||||||||||||||
828 | Qt::QueuedConnection); | - | ||||||||||||||||||
829 | QObject::connect(delegate, SIGNAL(redirected(QUrl,int,int)), | - | ||||||||||||||||||
830 | q, SLOT(onRedirected(QUrl,int,int)), | - | ||||||||||||||||||
831 | Qt::QueuedConnection); | - | ||||||||||||||||||
832 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
833 | QObject::connect(delegate, SIGNAL(sslConfigurationChanged(QSslConfiguration)), | - | ||||||||||||||||||
834 | q, SLOT(replySslConfigurationChanged(QSslConfiguration)), | - | ||||||||||||||||||
835 | Qt::QueuedConnection); | - | ||||||||||||||||||
836 | #endif | - | ||||||||||||||||||
837 | // Those need to report back, therefire BlockingQueuedConnection | - | ||||||||||||||||||
838 | QObject::connect(delegate, SIGNAL(authenticationRequired(QHttpNetworkRequest,QAuthenticator*)), | - | ||||||||||||||||||
839 | q, SLOT(httpAuthenticationRequired(QHttpNetworkRequest,QAuthenticator*)), | - | ||||||||||||||||||
840 | Qt::BlockingQueuedConnection); | - | ||||||||||||||||||
841 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
842 | QObject::connect(delegate, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), | - | ||||||||||||||||||
843 | q, SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), | - | ||||||||||||||||||
844 | Qt::BlockingQueuedConnection); | - | ||||||||||||||||||
845 | #endif | - | ||||||||||||||||||
846 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
847 | QObject::connect(delegate, SIGNAL(encrypted()), q, SLOT(replyEncrypted()), | - | ||||||||||||||||||
848 | Qt::BlockingQueuedConnection); | - | ||||||||||||||||||
849 | QObject::connect(delegate, SIGNAL(sslErrors(QList<QSslError>,bool*,QList<QSslError>*)), | - | ||||||||||||||||||
850 | q, SLOT(replySslErrors(QList<QSslError>,bool*,QList<QSslError>*)), | - | ||||||||||||||||||
851 | Qt::BlockingQueuedConnection); | - | ||||||||||||||||||
852 | QObject::connect(delegate, SIGNAL(preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*)), | - | ||||||||||||||||||
853 | q, SLOT(replyPreSharedKeyAuthenticationRequiredSlot(QSslPreSharedKeyAuthenticator*)), | - | ||||||||||||||||||
854 | Qt::BlockingQueuedConnection); | - | ||||||||||||||||||
855 | #endif | - | ||||||||||||||||||
856 | // This signal we will use to start the request. | - | ||||||||||||||||||
857 | QObject::connect(q, SIGNAL(startHttpRequest()), delegate, SLOT(startRequest())); | - | ||||||||||||||||||
858 | QObject::connect(q, SIGNAL(abortHttpRequest()), delegate, SLOT(abortRequest())); | - | ||||||||||||||||||
859 | - | |||||||||||||||||||
860 | // To throttle the connection. | - | ||||||||||||||||||
861 | QObject::connect(q, SIGNAL(readBufferSizeChanged(qint64)), delegate, SLOT(readBufferSizeChanged(qint64))); | - | ||||||||||||||||||
862 | QObject::connect(q, SIGNAL(readBufferFreed(qint64)), delegate, SLOT(readBufferFreed(qint64))); | - | ||||||||||||||||||
863 | - | |||||||||||||||||||
864 | if (uploadByteDevice) {
| 155-638 | ||||||||||||||||||
865 | QNonContiguousByteDeviceThreadForwardImpl *forwardUploadDevice = | - | ||||||||||||||||||
866 | new QNonContiguousByteDeviceThreadForwardImpl(uploadByteDevice->atEnd(), uploadByteDevice->size()); | - | ||||||||||||||||||
867 | forwardUploadDevice->setParent(delegate); // needed to make sure it is moved on moveToThread() | - | ||||||||||||||||||
868 | delegate->httpRequest.setUploadByteDevice(forwardUploadDevice); | - | ||||||||||||||||||
869 | - | |||||||||||||||||||
870 | // If the device in the user thread claims it has more data, keep the flow to HTTP thread going | - | ||||||||||||||||||
871 | QObject::connect(uploadByteDevice.data(), SIGNAL(readyRead()), | - | ||||||||||||||||||
872 | q, SLOT(uploadByteDeviceReadyReadSlot()), | - | ||||||||||||||||||
873 | Qt::QueuedConnection); | - | ||||||||||||||||||
874 | - | |||||||||||||||||||
875 | // From user thread to http thread: | - | ||||||||||||||||||
876 | QObject::connect(q, SIGNAL(haveUploadData(qint64,QByteArray,bool,qint64)), | - | ||||||||||||||||||
877 | forwardUploadDevice, SLOT(haveDataSlot(qint64,QByteArray,bool,qint64)), Qt::QueuedConnection); | - | ||||||||||||||||||
878 | QObject::connect(uploadByteDevice.data(), SIGNAL(readyRead()), | - | ||||||||||||||||||
879 | forwardUploadDevice, SIGNAL(readyRead()), | - | ||||||||||||||||||
880 | Qt::QueuedConnection); | - | ||||||||||||||||||
881 | - | |||||||||||||||||||
882 | // From http thread to user thread: | - | ||||||||||||||||||
883 | QObject::connect(forwardUploadDevice, SIGNAL(wantData(qint64)), | - | ||||||||||||||||||
884 | q, SLOT(wantUploadDataSlot(qint64))); | - | ||||||||||||||||||
885 | QObject::connect(forwardUploadDevice,SIGNAL(processedData(qint64, qint64)), | - | ||||||||||||||||||
886 | q, SLOT(sentUploadDataSlot(qint64,qint64))); | - | ||||||||||||||||||
887 | QObject::connect(forwardUploadDevice, SIGNAL(resetData(bool*)), | - | ||||||||||||||||||
888 | q, SLOT(resetUploadDataSlot(bool*)), | - | ||||||||||||||||||
889 | Qt::BlockingQueuedConnection); // this is the only one with BlockingQueued! | - | ||||||||||||||||||
890 | } executed 155 times by 3 tests: end of block Executed by:
| 155 | ||||||||||||||||||
891 | } else if (synchronous) { executed 793 times by 8 tests: end of block Executed by:
| 0-793 | ||||||||||||||||||
892 | QObject::connect(q, SIGNAL(startHttpRequestSynchronously()), delegate, SLOT(startRequestSynchronously()), Qt::BlockingQueuedConnection); | - | ||||||||||||||||||
893 | - | |||||||||||||||||||
894 | if (uploadByteDevice) {
| 35-41 | ||||||||||||||||||
895 | // For the synchronous HTTP use case the use thread (this one here) is blocked | - | ||||||||||||||||||
896 | // so we cannot use the asynchronous upload architecture. | - | ||||||||||||||||||
897 | // We therefore won't use the QNonContiguousByteDeviceThreadForwardImpl but directly | - | ||||||||||||||||||
898 | // use the uploadByteDevice provided to us by the QNetworkReplyImpl. | - | ||||||||||||||||||
899 | // The code that is in start() makes sure it is safe to use from a thread | - | ||||||||||||||||||
900 | // since it only wraps a QRingBuffer | - | ||||||||||||||||||
901 | delegate->httpRequest.setUploadByteDevice(uploadByteDevice.data()); | - | ||||||||||||||||||
902 | } executed 41 times by 1 test: end of block Executed by:
| 41 | ||||||||||||||||||
903 | } executed 76 times by 1 test: end of block Executed by:
| 76 | ||||||||||||||||||
904 | - | |||||||||||||||||||
905 | - | |||||||||||||||||||
906 | // Move the delegate to the http thread | - | ||||||||||||||||||
907 | delegate->moveToThread(thread); | - | ||||||||||||||||||
908 | // This call automatically moves the uploadDevice too for the asynchronous case. | - | ||||||||||||||||||
909 | - | |||||||||||||||||||
910 | // Prepare timers for progress notifications | - | ||||||||||||||||||
911 | downloadProgressSignalChoke.start(); | - | ||||||||||||||||||
912 | uploadProgressSignalChoke.invalidate(); | - | ||||||||||||||||||
913 | - | |||||||||||||||||||
914 | // Send an signal to the delegate so it starts working in the other thread | - | ||||||||||||||||||
915 | if (synchronous) {
| 76-793 | ||||||||||||||||||
916 | emit q->startHttpRequestSynchronously(); // This one is BlockingQueuedConnection, so it will return when all work is done | - | ||||||||||||||||||
917 | - | |||||||||||||||||||
918 | if (delegate->incomingErrorCode != QNetworkReply::NoError) {
| 13-63 | ||||||||||||||||||
919 | replyDownloadMetaData | - | ||||||||||||||||||
920 | (delegate->incomingHeaders, | - | ||||||||||||||||||
921 | delegate->incomingStatusCode, | - | ||||||||||||||||||
922 | delegate->incomingReasonPhrase, | - | ||||||||||||||||||
923 | delegate->isPipeliningUsed, | - | ||||||||||||||||||
924 | QSharedPointer<char>(), | - | ||||||||||||||||||
925 | delegate->incomingContentLength, | - | ||||||||||||||||||
926 | delegate->isSpdyUsed); | - | ||||||||||||||||||
927 | replyDownloadData(delegate->synchronousDownloadData); | - | ||||||||||||||||||
928 | httpError(delegate->incomingErrorCode, delegate->incomingErrorDetail); | - | ||||||||||||||||||
929 | } else { executed 13 times by 1 test: end of block Executed by:
| 13 | ||||||||||||||||||
930 | replyDownloadMetaData | - | ||||||||||||||||||
931 | (delegate->incomingHeaders, | - | ||||||||||||||||||
932 | delegate->incomingStatusCode, | - | ||||||||||||||||||
933 | delegate->incomingReasonPhrase, | - | ||||||||||||||||||
934 | delegate->isPipeliningUsed, | - | ||||||||||||||||||
935 | QSharedPointer<char>(), | - | ||||||||||||||||||
936 | delegate->incomingContentLength, | - | ||||||||||||||||||
937 | delegate->isSpdyUsed); | - | ||||||||||||||||||
938 | replyDownloadData(delegate->synchronousDownloadData); | - | ||||||||||||||||||
939 | } executed 63 times by 1 test: end of block Executed by:
| 63 | ||||||||||||||||||
940 | - | |||||||||||||||||||
941 | thread->quit(); | - | ||||||||||||||||||
942 | thread->wait(5000); | - | ||||||||||||||||||
943 | if (thread->isFinished())
| 0-76 | ||||||||||||||||||
944 | delete thread; executed 76 times by 1 test: delete thread; Executed by:
| 76 | ||||||||||||||||||
945 | else | - | ||||||||||||||||||
946 | QObject::connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); never executed: QObject::connect(thread, qFlagLocation("2""finished()" "\0" __FILE__ ":" "946"), thread, qFlagLocation("1""deleteLater()" "\0" __FILE__ ":" "946")); | 0 | ||||||||||||||||||
947 | - | |||||||||||||||||||
948 | finished(); | - | ||||||||||||||||||
949 | } else { executed 76 times by 1 test: end of block Executed by:
| 76 | ||||||||||||||||||
950 | emit q->startHttpRequest(); // Signal to the HTTP thread and go back to user. | - | ||||||||||||||||||
951 | } executed 793 times by 8 tests: end of block Executed by:
| 793 | ||||||||||||||||||
952 | } | - | ||||||||||||||||||
953 | - | |||||||||||||||||||
954 | void QNetworkReplyHttpImplPrivate::invalidateCache() | - | ||||||||||||||||||
955 | { | - | ||||||||||||||||||
956 | QAbstractNetworkCache *nc = managerPrivate->networkCache; | - | ||||||||||||||||||
957 | if (nc)
| 2-205 | ||||||||||||||||||
958 | nc->remove(httpRequest.url()); executed 2 times by 1 test: nc->remove(httpRequest.url()); Executed by:
| 2 | ||||||||||||||||||
959 | } executed 207 times by 3 tests: end of block Executed by:
| 207 | ||||||||||||||||||
960 | - | |||||||||||||||||||
961 | void QNetworkReplyHttpImplPrivate::initCacheSaveDevice() | - | ||||||||||||||||||
962 | { | - | ||||||||||||||||||
963 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
964 | - | |||||||||||||||||||
965 | // The disk cache does not support partial content, so don't even try to | - | ||||||||||||||||||
966 | // save any such content into the cache. | - | ||||||||||||||||||
967 | if (q->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 206) {
| 1-61 | ||||||||||||||||||
968 | cacheEnabled = false; | - | ||||||||||||||||||
969 | return; executed 1 time by 1 test: return; Executed by:
| 1 | ||||||||||||||||||
970 | } | - | ||||||||||||||||||
971 | - | |||||||||||||||||||
972 | // save the meta data | - | ||||||||||||||||||
973 | QNetworkCacheMetaData metaData; | - | ||||||||||||||||||
974 | metaData.setUrl(url); | - | ||||||||||||||||||
975 | metaData = fetchCacheMetaData(metaData); | - | ||||||||||||||||||
976 | - | |||||||||||||||||||
977 | // save the redirect request also in the cache | - | ||||||||||||||||||
978 | QVariant redirectionTarget = q->attribute(QNetworkRequest::RedirectionTargetAttribute); | - | ||||||||||||||||||
979 | if (redirectionTarget.isValid()) {
| 0-61 | ||||||||||||||||||
980 | QNetworkCacheMetaData::AttributesMap attributes = metaData.attributes(); | - | ||||||||||||||||||
981 | attributes.insert(QNetworkRequest::RedirectionTargetAttribute, redirectionTarget); | - | ||||||||||||||||||
982 | metaData.setAttributes(attributes); | - | ||||||||||||||||||
983 | } never executed: end of block | 0 | ||||||||||||||||||
984 | - | |||||||||||||||||||
985 | cacheSaveDevice = managerPrivate->networkCache->prepare(metaData); | - | ||||||||||||||||||
986 | - | |||||||||||||||||||
987 | if (cacheSaveDevice)
| 7-54 | ||||||||||||||||||
988 | q->connect(cacheSaveDevice, SIGNAL(aboutToClose()), SLOT(_q_cacheSaveDeviceAboutToClose())); executed 54 times by 3 tests: q->connect(cacheSaveDevice, qFlagLocation("2""aboutToClose()" "\0" __FILE__ ":" "988"), qFlagLocation("1""_q_cacheSaveDeviceAboutToClose()" "\0" __FILE__ ":" "988")); Executed by:
| 54 | ||||||||||||||||||
989 | - | |||||||||||||||||||
990 | if (!cacheSaveDevice || (cacheSaveDevice && !cacheSaveDevice->isOpen())) {
| 0-54 | ||||||||||||||||||
991 | if (cacheSaveDevice && !cacheSaveDevice->isOpen())
| 0-7 | ||||||||||||||||||
992 | qCritical("QNetworkReplyImpl: network cache returned a device that is not open -- " never executed: QMessageLogger(__FILE__, 992, __PRETTY_FUNCTION__).critical("QNetworkReplyImpl: network cache returned a device that is not open -- " "class %s probably needs to be fixed", managerPrivate->networkCache->metaObject()->className()); | 0 | ||||||||||||||||||
993 | "class %s probably needs to be fixed", never executed: QMessageLogger(__FILE__, 992, __PRETTY_FUNCTION__).critical("QNetworkReplyImpl: network cache returned a device that is not open -- " "class %s probably needs to be fixed", managerPrivate->networkCache->metaObject()->className()); | 0 | ||||||||||||||||||
994 | managerPrivate->networkCache->metaObject()->className()); never executed: QMessageLogger(__FILE__, 992, __PRETTY_FUNCTION__).critical("QNetworkReplyImpl: network cache returned a device that is not open -- " "class %s probably needs to be fixed", managerPrivate->networkCache->metaObject()->className()); | 0 | ||||||||||||||||||
995 | - | |||||||||||||||||||
996 | managerPrivate->networkCache->remove(url); | - | ||||||||||||||||||
997 | cacheSaveDevice = 0; | - | ||||||||||||||||||
998 | cacheEnabled = false; | - | ||||||||||||||||||
999 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||
1000 | } executed 61 times by 3 tests: end of block Executed by:
| 61 | ||||||||||||||||||
1001 | - | |||||||||||||||||||
1002 | void QNetworkReplyHttpImplPrivate::replyDownloadData(QByteArray d) | - | ||||||||||||||||||
1003 | { | - | ||||||||||||||||||
1004 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
1005 | - | |||||||||||||||||||
1006 | // If we're closed just ignore this data | - | ||||||||||||||||||
1007 | if (!q->isOpen())
| 1-5931 | ||||||||||||||||||
1008 | return; executed 1 time by 1 test: return; Executed by:
| 1 | ||||||||||||||||||
1009 | - | |||||||||||||||||||
1010 | int pendingSignals = (int)pendingDownloadDataEmissions->fetchAndAddAcquire(-1) - 1; | - | ||||||||||||||||||
1011 | - | |||||||||||||||||||
1012 | if (pendingSignals > 0) {
| 1312-4619 | ||||||||||||||||||
1013 | // Some more signal emissions to this slot are pending. | - | ||||||||||||||||||
1014 | // Instead of writing the downstream data, we wait | - | ||||||||||||||||||
1015 | // and do it in the next call we get | - | ||||||||||||||||||
1016 | // (signal comppression) | - | ||||||||||||||||||
1017 | pendingDownloadData.append(d); | - | ||||||||||||||||||
1018 | return; executed 1312 times by 2 tests: return; Executed by:
| 1312 | ||||||||||||||||||
1019 | } | - | ||||||||||||||||||
1020 | - | |||||||||||||||||||
1021 | pendingDownloadData.append(d); | - | ||||||||||||||||||
1022 | d.clear(); | - | ||||||||||||||||||
1023 | // We need to usa a copy for calling writeDownstreamData as we could | - | ||||||||||||||||||
1024 | // possibly recurse into this this function when we call | - | ||||||||||||||||||
1025 | // appendDownstreamDataSignalEmissions because the user might call | - | ||||||||||||||||||
1026 | // processEvents() or spin an event loop when this occur. | - | ||||||||||||||||||
1027 | QByteDataBuffer pendingDownloadDataCopy = pendingDownloadData; | - | ||||||||||||||||||
1028 | pendingDownloadData.clear(); | - | ||||||||||||||||||
1029 | - | |||||||||||||||||||
1030 | if (cacheEnabled && isCachingAllowed() && !cacheSaveDevice) {
| 0-4574 | ||||||||||||||||||
1031 | initCacheSaveDevice(); | - | ||||||||||||||||||
1032 | } executed 45 times by 2 tests: end of block Executed by:
| 45 | ||||||||||||||||||
1033 | - | |||||||||||||||||||
1034 | qint64 bytesWritten = 0; | - | ||||||||||||||||||
1035 | for (int i = 0; i < pendingDownloadDataCopy.bufferCount(); i++) {
| 4619-5929 | ||||||||||||||||||
1036 | QByteArray const &item = pendingDownloadDataCopy[i]; | - | ||||||||||||||||||
1037 | - | |||||||||||||||||||
1038 | // This is going to look a little strange. When downloading data while a | - | ||||||||||||||||||
1039 | // HTTP redirect is happening (and enabled), we write the redirect | - | ||||||||||||||||||
1040 | // response to the cache. However, we do not append it to our internal | - | ||||||||||||||||||
1041 | // buffer as that will contain the response data only for the final | - | ||||||||||||||||||
1042 | // response | - | ||||||||||||||||||
1043 | if (cacheSaveDevice)
| 44-5885 | ||||||||||||||||||
1044 | cacheSaveDevice->write(item.constData(), item.size()); executed 44 times by 2 tests: cacheSaveDevice->write(item.constData(), item.size()); Executed by:
| 44 | ||||||||||||||||||
1045 | - | |||||||||||||||||||
1046 | if (!isHttpRedirectResponse())
| 0-5929 | ||||||||||||||||||
1047 | downloadMultiBuffer.append(item); executed 5929 times by 4 tests: downloadMultiBuffer.append(item); Executed by:
| 5929 | ||||||||||||||||||
1048 | - | |||||||||||||||||||
1049 | bytesWritten += item.size(); | - | ||||||||||||||||||
1050 | } executed 5929 times by 4 tests: end of block Executed by:
| 5929 | ||||||||||||||||||
1051 | pendingDownloadDataCopy.clear(); | - | ||||||||||||||||||
1052 | - | |||||||||||||||||||
1053 | QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); | - | ||||||||||||||||||
1054 | if (preMigrationDownloaded != Q_INT64_C(-1))
| 0-4619 | ||||||||||||||||||
1055 | totalSize = totalSize.toLongLong() + preMigrationDownloaded; never executed: totalSize = totalSize.toLongLong() + preMigrationDownloaded; | 0 | ||||||||||||||||||
1056 | - | |||||||||||||||||||
1057 | if (isHttpRedirectResponse())
| 0-4619 | ||||||||||||||||||
1058 | return; never executed: return; | 0 | ||||||||||||||||||
1059 | - | |||||||||||||||||||
1060 | bytesDownloaded += bytesWritten; | - | ||||||||||||||||||
1061 | - | |||||||||||||||||||
1062 | emit q->readyRead(); | - | ||||||||||||||||||
1063 | // emit readyRead before downloadProgress incase this will cause events to be | - | ||||||||||||||||||
1064 | // processed and we get into a recursive call (as in QProgressDialog). | - | ||||||||||||||||||
1065 | if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval) {
| 46-4573 | ||||||||||||||||||
1066 | downloadProgressSignalChoke.restart(); | - | ||||||||||||||||||
1067 | emit q->downloadProgress(bytesDownloaded, | - | ||||||||||||||||||
1068 | totalSize.isNull() ? Q_INT64_C(-1) : totalSize.toLongLong()); | - | ||||||||||||||||||
1069 | } executed 46 times by 2 tests: end of block Executed by:
| 46 | ||||||||||||||||||
1070 | - | |||||||||||||||||||
1071 | } executed 4619 times by 4 tests: end of block Executed by:
| 4619 | ||||||||||||||||||
1072 | - | |||||||||||||||||||
1073 | void QNetworkReplyHttpImplPrivate::replyFinished() | - | ||||||||||||||||||
1074 | { | - | ||||||||||||||||||
1075 | // We are already loading from cache, we still however | - | ||||||||||||||||||
1076 | // got this signal because it was posted already | - | ||||||||||||||||||
1077 | if (loadingFromCache)
| 5-756 | ||||||||||||||||||
1078 | return; executed 5 times by 1 test: return; Executed by:
| 5 | ||||||||||||||||||
1079 | - | |||||||||||||||||||
1080 | finished(); | - | ||||||||||||||||||
1081 | } executed 756 times by 7 tests: end of block Executed by:
| 756 | ||||||||||||||||||
1082 | - | |||||||||||||||||||
1083 | QNetworkAccessManager::Operation QNetworkReplyHttpImplPrivate::getRedirectOperation(QNetworkAccessManager::Operation currentOp, int httpStatus) | - | ||||||||||||||||||
1084 | { | - | ||||||||||||||||||
1085 | // HTTP status code can be used to decide if we can redirect with a GET | - | ||||||||||||||||||
1086 | // operation or not. See http://www.ietf.org/rfc/rfc2616.txt [Sec 10.3] for | - | ||||||||||||||||||
1087 | // more details | - | ||||||||||||||||||
1088 | Q_UNUSED(httpStatus); | - | ||||||||||||||||||
1089 | - | |||||||||||||||||||
1090 | switch (currentOp) { | - | ||||||||||||||||||
1091 | case QNetworkAccessManager::HeadOperation: never executed: case QNetworkAccessManager::HeadOperation: | 0 | ||||||||||||||||||
1092 | return QNetworkAccessManager::HeadOperation; never executed: return QNetworkAccessManager::HeadOperation; | 0 | ||||||||||||||||||
1093 | default: executed 5 times by 1 test: default: Executed by:
| 5 | ||||||||||||||||||
1094 | break; executed 5 times by 1 test: break; Executed by:
| 5 | ||||||||||||||||||
1095 | } | - | ||||||||||||||||||
1096 | // For now, we're always returning GET for anything other than HEAD | - | ||||||||||||||||||
1097 | return QNetworkAccessManager::GetOperation; executed 5 times by 1 test: return QNetworkAccessManager::GetOperation; Executed by:
| 5 | ||||||||||||||||||
1098 | } | - | ||||||||||||||||||
1099 | - | |||||||||||||||||||
1100 | bool QNetworkReplyHttpImplPrivate::isHttpRedirectResponse() const | - | ||||||||||||||||||
1101 | { | - | ||||||||||||||||||
1102 | return httpRequest.isFollowRedirects() && QHttpNetworkReply::isHttpRedirect(statusCode); executed 13590 times by 7 tests: return httpRequest.isFollowRedirects() && QHttpNetworkReply::isHttpRedirect(statusCode); Executed by:
| 4-13590 | ||||||||||||||||||
1103 | } | - | ||||||||||||||||||
1104 | - | |||||||||||||||||||
1105 | QNetworkRequest QNetworkReplyHttpImplPrivate::createRedirectRequest(const QNetworkRequest &originalRequest, | - | ||||||||||||||||||
1106 | const QUrl &url, | - | ||||||||||||||||||
1107 | int maxRedirectsRemaining) | - | ||||||||||||||||||
1108 | { | - | ||||||||||||||||||
1109 | QNetworkRequest newRequest(originalRequest); | - | ||||||||||||||||||
1110 | newRequest.setUrl(url); | - | ||||||||||||||||||
1111 | newRequest.setMaximumRedirectsAllowed(maxRedirectsRemaining); | - | ||||||||||||||||||
1112 | - | |||||||||||||||||||
1113 | return newRequest; executed 5 times by 1 test: return newRequest; Executed by:
| 5 | ||||||||||||||||||
1114 | } | - | ||||||||||||||||||
1115 | - | |||||||||||||||||||
1116 | void QNetworkReplyHttpImplPrivate::onRedirected(const QUrl &redirectUrl, int httpStatus, int maxRedirectsRemaining) | - | ||||||||||||||||||
1117 | { | - | ||||||||||||||||||
1118 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
1119 | - | |||||||||||||||||||
1120 | if (isFinished)
| 0-5 | ||||||||||||||||||
1121 | return; never executed: return; | 0 | ||||||||||||||||||
1122 | - | |||||||||||||||||||
1123 | if (httpRequest.isFollowRedirects()) // update the reply's url as it could've changed
| 0-5 | ||||||||||||||||||
1124 | url = redirectUrl; executed 5 times by 1 test: url = redirectUrl; Executed by:
| 5 | ||||||||||||||||||
1125 | - | |||||||||||||||||||
1126 | QNetworkRequest redirectRequest = createRedirectRequest(originalRequest, redirectUrl, maxRedirectsRemaining); | - | ||||||||||||||||||
1127 | operation = getRedirectOperation(operation, httpStatus); | - | ||||||||||||||||||
1128 | - | |||||||||||||||||||
1129 | cookedHeaders.clear(); | - | ||||||||||||||||||
1130 | - | |||||||||||||||||||
1131 | if (managerPrivate->httpThread)
| 0-5 | ||||||||||||||||||
1132 | managerPrivate->httpThread->disconnect(); executed 5 times by 1 test: managerPrivate->httpThread->disconnect(); Executed by:
| 5 | ||||||||||||||||||
1133 | - | |||||||||||||||||||
1134 | // Recurse | - | ||||||||||||||||||
1135 | QMetaObject::invokeMethod(q, "start", Qt::QueuedConnection, | - | ||||||||||||||||||
1136 | Q_ARG(QNetworkRequest, redirectRequest)); | - | ||||||||||||||||||
1137 | - | |||||||||||||||||||
1138 | emit q->redirected(redirectUrl); | - | ||||||||||||||||||
1139 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||
1140 | - | |||||||||||||||||||
1141 | void QNetworkReplyHttpImplPrivate::checkForRedirect(const int statusCode) | - | ||||||||||||||||||
1142 | { | - | ||||||||||||||||||
1143 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
1144 | switch (statusCode) { | - | ||||||||||||||||||
1145 | case 301: // Moved Permanently executed 3 times by 1 test: case 301: Executed by:
| 3 | ||||||||||||||||||
1146 | case 302: // Found never executed: case 302: | 0 | ||||||||||||||||||
1147 | case 303: // See Other never executed: case 303: | 0 | ||||||||||||||||||
1148 | case 307: // Temporary Redirect never executed: case 307: | 0 | ||||||||||||||||||
1149 | // What do we do about the caching of the HTML note? | - | ||||||||||||||||||
1150 | // The response to a 303 MUST NOT be cached, while the response to | - | ||||||||||||||||||
1151 | // all of the others is cacheable if the headers indicate it to be | - | ||||||||||||||||||
1152 | QByteArray header = q->rawHeader("location"); | - | ||||||||||||||||||
1153 | QUrl url = QUrl(QString::fromUtf8(header)); | - | ||||||||||||||||||
1154 | if (!url.isValid())
| 0-3 | ||||||||||||||||||
1155 | url = QUrl(QLatin1String(header)); never executed: url = QUrl(QLatin1String(header)); | 0 | ||||||||||||||||||
1156 | q->setAttribute(QNetworkRequest::RedirectionTargetAttribute, url); | - | ||||||||||||||||||
1157 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
1158 | } executed 817 times by 6 tests: end of block Executed by:
| 817 | ||||||||||||||||||
1159 | - | |||||||||||||||||||
1160 | void QNetworkReplyHttpImplPrivate::replyDownloadMetaData | - | ||||||||||||||||||
1161 | (QList<QPair<QByteArray,QByteArray> > hm, | - | ||||||||||||||||||
1162 | int sc,QString rp,bool pu, | - | ||||||||||||||||||
1163 | QSharedPointer<char> db, | - | ||||||||||||||||||
1164 | qint64 contentLength, bool spdyWasUsed) | - | ||||||||||||||||||
1165 | { | - | ||||||||||||||||||
1166 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
1167 | Q_UNUSED(contentLength); | - | ||||||||||||||||||
1168 | - | |||||||||||||||||||
1169 | statusCode = sc; | - | ||||||||||||||||||
1170 | reasonPhrase = rp; | - | ||||||||||||||||||
1171 | - | |||||||||||||||||||
1172 | // Download buffer | - | ||||||||||||||||||
1173 | if (!db.isNull()) {
| 364-432 | ||||||||||||||||||
1174 | downloadBufferPointer = db; | - | ||||||||||||||||||
1175 | downloadZerocopyBuffer = downloadBufferPointer.data(); | - | ||||||||||||||||||
1176 | downloadBufferCurrentSize = 0; | - | ||||||||||||||||||
1177 | q->setAttribute(QNetworkRequest::DownloadBufferAttribute, QVariant::fromValue<QSharedPointer<char> > (downloadBufferPointer)); | - | ||||||||||||||||||
1178 | } executed 364 times by 3 tests: end of block Executed by:
| 364 | ||||||||||||||||||
1179 | - | |||||||||||||||||||
1180 | q->setAttribute(QNetworkRequest::HttpPipeliningWasUsedAttribute, pu); | - | ||||||||||||||||||
1181 | q->setAttribute(QNetworkRequest::SpdyWasUsedAttribute, spdyWasUsed); | - | ||||||||||||||||||
1182 | - | |||||||||||||||||||
1183 | // reconstruct the HTTP header | - | ||||||||||||||||||
1184 | QList<QPair<QByteArray, QByteArray> > headerMap = hm; | - | ||||||||||||||||||
1185 | QList<QPair<QByteArray, QByteArray> >::ConstIterator it = headerMap.constBegin(), | - | ||||||||||||||||||
1186 | end = headerMap.constEnd(); | - | ||||||||||||||||||
1187 | for (; it != end; ++it) {
| 796-5044 | ||||||||||||||||||
1188 | QByteArray value = q->rawHeader(it->first); | - | ||||||||||||||||||
1189 | - | |||||||||||||||||||
1190 | // Reset any previous "location" header set in the reply. In case of | - | ||||||||||||||||||
1191 | // redirects, we don't want to 'append' multiple location header values, | - | ||||||||||||||||||
1192 | // rather we keep only the latest one | - | ||||||||||||||||||
1193 | if (it->first.toLower() == "location")
| 43-5001 | ||||||||||||||||||
1194 | value.clear(); executed 43 times by 2 tests: value.clear(); Executed by:
| 43 | ||||||||||||||||||
1195 | - | |||||||||||||||||||
1196 | if (!value.isEmpty()) {
| 5-5039 | ||||||||||||||||||
1197 | // Why are we appending values for headers which are already | - | ||||||||||||||||||
1198 | // present? | - | ||||||||||||||||||
1199 | if (qstricmp(it->first.constData(), "set-cookie") == 0)
| 2-3 | ||||||||||||||||||
1200 | value += '\n'; executed 2 times by 1 test: value += '\n'; Executed by:
| 2 | ||||||||||||||||||
1201 | else | - | ||||||||||||||||||
1202 | value += ", "; executed 3 times by 1 test: value += ", "; Executed by:
| 3 | ||||||||||||||||||
1203 | } | - | ||||||||||||||||||
1204 | value += it->second; | - | ||||||||||||||||||
1205 | q->setRawHeader(it->first, value); | - | ||||||||||||||||||
1206 | } executed 5044 times by 6 tests: end of block Executed by:
| 5044 | ||||||||||||||||||
1207 | - | |||||||||||||||||||
1208 | q->setAttribute(QNetworkRequest::HttpStatusCodeAttribute, statusCode); | - | ||||||||||||||||||
1209 | q->setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, reasonPhrase); | - | ||||||||||||||||||
1210 | - | |||||||||||||||||||
1211 | // is it a redirection? | - | ||||||||||||||||||
1212 | if (!isHttpRedirectResponse())
| 6-790 | ||||||||||||||||||
1213 | checkForRedirect(statusCode); executed 790 times by 6 tests: checkForRedirect(statusCode); Executed by:
| 790 | ||||||||||||||||||
1214 | - | |||||||||||||||||||
1215 | if (statusCode >= 500 && statusCode < 600) {
| 0-795 | ||||||||||||||||||
1216 | QAbstractNetworkCache *nc = managerPrivate->networkCache; | - | ||||||||||||||||||
1217 | if (nc) {
| 0-1 | ||||||||||||||||||
1218 | QNetworkCacheMetaData metaData = nc->metaData(httpRequest.url()); | - | ||||||||||||||||||
1219 | QNetworkHeadersPrivate cacheHeaders; | - | ||||||||||||||||||
1220 | cacheHeaders.setAllRawHeaders(metaData.rawHeaders()); | - | ||||||||||||||||||
1221 | QNetworkHeadersPrivate::RawHeadersList::ConstIterator it; | - | ||||||||||||||||||
1222 | it = cacheHeaders.findRawHeader("Cache-Control"); | - | ||||||||||||||||||
1223 | bool mustReValidate = false; | - | ||||||||||||||||||
1224 | if (it != cacheHeaders.rawHeaders.constEnd()) {
| 0 | ||||||||||||||||||
1225 | QHash<QByteArray, QByteArray> cacheControl = parseHttpOptionHeader(it->second); | - | ||||||||||||||||||
1226 | if (cacheControl.contains("must-revalidate"))
| 0 | ||||||||||||||||||
1227 | mustReValidate = true; never executed: mustReValidate = true; | 0 | ||||||||||||||||||
1228 | } never executed: end of block | 0 | ||||||||||||||||||
1229 | if (!mustReValidate && sendCacheContents(metaData))
| 0 | ||||||||||||||||||
1230 | return; never executed: return; | 0 | ||||||||||||||||||
1231 | } never executed: end of block | 0 | ||||||||||||||||||
1232 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
1233 | - | |||||||||||||||||||
1234 | if (statusCode == 304) {
| 9-787 | ||||||||||||||||||
1235 | #if defined(QNETWORKACCESSHTTPBACKEND_DEBUG) | - | ||||||||||||||||||
1236 | qDebug() << "Received a 304 from" << request.url(); | - | ||||||||||||||||||
1237 | #endif | - | ||||||||||||||||||
1238 | QAbstractNetworkCache *nc = managerPrivate->networkCache; | - | ||||||||||||||||||
1239 | if (nc) {
| 0-9 | ||||||||||||||||||
1240 | QNetworkCacheMetaData oldMetaData = nc->metaData(httpRequest.url()); | - | ||||||||||||||||||
1241 | QNetworkCacheMetaData metaData = fetchCacheMetaData(oldMetaData); | - | ||||||||||||||||||
1242 | if (oldMetaData != metaData)
| 0-9 | ||||||||||||||||||
1243 | nc->updateMetaData(metaData); executed 9 times by 2 tests: nc->updateMetaData(metaData); Executed by:
| 9 | ||||||||||||||||||
1244 | if (sendCacheContents(metaData))
| 0-9 | ||||||||||||||||||
1245 | return; executed 9 times by 2 tests: return; Executed by:
| 9 | ||||||||||||||||||
1246 | } never executed: end of block | 0 | ||||||||||||||||||
1247 | } never executed: end of block | 0 | ||||||||||||||||||
1248 | - | |||||||||||||||||||
1249 | - | |||||||||||||||||||
1250 | if (statusCode != 304 && statusCode != 303) {
| 0-787 | ||||||||||||||||||
1251 | if (!isCachingEnabled())
| 0-787 | ||||||||||||||||||
1252 | setCachingEnabled(true); executed 787 times by 6 tests: setCachingEnabled(true); Executed by:
| 787 | ||||||||||||||||||
1253 | } executed 787 times by 6 tests: end of block Executed by:
| 787 | ||||||||||||||||||
1254 | - | |||||||||||||||||||
1255 | _q_metaDataChanged(); | - | ||||||||||||||||||
1256 | } executed 787 times by 6 tests: end of block Executed by:
| 787 | ||||||||||||||||||
1257 | - | |||||||||||||||||||
1258 | void QNetworkReplyHttpImplPrivate::replyDownloadProgressSlot(qint64 bytesReceived, qint64 bytesTotal) | - | ||||||||||||||||||
1259 | { | - | ||||||||||||||||||
1260 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
1261 | - | |||||||||||||||||||
1262 | // If we're closed just ignore this data | - | ||||||||||||||||||
1263 | if (!q->isOpen())
| 0-1495 | ||||||||||||||||||
1264 | return; never executed: return; | 0 | ||||||||||||||||||
1265 | - | |||||||||||||||||||
1266 | // we can be sure here that there is a download buffer | - | ||||||||||||||||||
1267 | - | |||||||||||||||||||
1268 | int pendingSignals = (int)pendingDownloadProgressEmissions->fetchAndAddAcquire(-1) - 1; | - | ||||||||||||||||||
1269 | if (pendingSignals > 0) {
| 199-1296 | ||||||||||||||||||
1270 | // Let's ignore this signal and look at the next one coming in | - | ||||||||||||||||||
1271 | // (signal comppression) | - | ||||||||||||||||||
1272 | return; executed 199 times by 1 test: return; Executed by:
| 199 | ||||||||||||||||||
1273 | } | - | ||||||||||||||||||
1274 | - | |||||||||||||||||||
1275 | if (!q->isOpen())
| 0-1296 | ||||||||||||||||||
1276 | return; never executed: return; | 0 | ||||||||||||||||||
1277 | - | |||||||||||||||||||
1278 | if (cacheEnabled && isCachingAllowed() && bytesReceived == bytesTotal) {
| 1-1277 | ||||||||||||||||||
1279 | // Write everything in one go if we use a download buffer. might be more performant. | - | ||||||||||||||||||
1280 | initCacheSaveDevice(); | - | ||||||||||||||||||
1281 | // need to check again if cache enabled and device exists | - | ||||||||||||||||||
1282 | if (cacheSaveDevice && cacheEnabled)
| 0-10 | ||||||||||||||||||
1283 | cacheSaveDevice->write(downloadZerocopyBuffer, bytesTotal); executed 10 times by 2 tests: cacheSaveDevice->write(downloadZerocopyBuffer, bytesTotal); Executed by:
| 10 | ||||||||||||||||||
1284 | // FIXME where is it closed? | - | ||||||||||||||||||
1285 | } executed 17 times by 2 tests: end of block Executed by:
| 17 | ||||||||||||||||||
1286 | - | |||||||||||||||||||
1287 | if (isHttpRedirectResponse())
| 0-1296 | ||||||||||||||||||
1288 | return; never executed: return; | 0 | ||||||||||||||||||
1289 | - | |||||||||||||||||||
1290 | bytesDownloaded = bytesReceived; | - | ||||||||||||||||||
1291 | - | |||||||||||||||||||
1292 | downloadBufferCurrentSize = bytesReceived; | - | ||||||||||||||||||
1293 | - | |||||||||||||||||||
1294 | // Only emit readyRead when actual data is there | - | ||||||||||||||||||
1295 | // emit readyRead before downloadProgress incase this will cause events to be | - | ||||||||||||||||||
1296 | // processed and we get into a recursive call (as in QProgressDialog). | - | ||||||||||||||||||
1297 | if (bytesDownloaded > 0)
| 0-1296 | ||||||||||||||||||
1298 | emit q->readyRead(); executed 1296 times by 3 tests: q->readyRead(); Executed by:
| 1296 | ||||||||||||||||||
1299 | if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval) {
| 66-1230 | ||||||||||||||||||
1300 | downloadProgressSignalChoke.restart(); | - | ||||||||||||||||||
1301 | emit q->downloadProgress(bytesDownloaded, bytesTotal); | - | ||||||||||||||||||
1302 | } executed 66 times by 1 test: end of block Executed by:
| 66 | ||||||||||||||||||
1303 | } executed 1296 times by 3 tests: end of block Executed by:
| 1296 | ||||||||||||||||||
1304 | - | |||||||||||||||||||
1305 | void QNetworkReplyHttpImplPrivate::httpAuthenticationRequired(const QHttpNetworkRequest &request, | - | ||||||||||||||||||
1306 | QAuthenticator *auth) | - | ||||||||||||||||||
1307 | { | - | ||||||||||||||||||
1308 | managerPrivate->authenticationRequired(auth, q_func(), synchronous, url, &urlForLastAuthentication, request.withCredentials()); | - | ||||||||||||||||||
1309 | } executed 124 times by 1 test: end of block Executed by:
| 124 | ||||||||||||||||||
1310 | - | |||||||||||||||||||
1311 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
1312 | void QNetworkReplyHttpImplPrivate::proxyAuthenticationRequired(const QNetworkProxy &proxy, | - | ||||||||||||||||||
1313 | QAuthenticator *authenticator) | - | ||||||||||||||||||
1314 | { | - | ||||||||||||||||||
1315 | managerPrivate->proxyAuthenticationRequired(request.url(), proxy, synchronous, authenticator, &lastProxyAuthentication); | - | ||||||||||||||||||
1316 | } executed 68 times by 2 tests: end of block Executed by:
| 68 | ||||||||||||||||||
1317 | #endif | - | ||||||||||||||||||
1318 | - | |||||||||||||||||||
1319 | void QNetworkReplyHttpImplPrivate::httpError(QNetworkReply::NetworkError errorCode, | - | ||||||||||||||||||
1320 | const QString &errorString) | - | ||||||||||||||||||
1321 | { | - | ||||||||||||||||||
1322 | #if defined(QNETWORKACCESSHTTPBACKEND_DEBUG) | - | ||||||||||||||||||
1323 | qDebug() << "http error!" << errorCode << errorString; | - | ||||||||||||||||||
1324 | #endif | - | ||||||||||||||||||
1325 | - | |||||||||||||||||||
1326 | // FIXME? | - | ||||||||||||||||||
1327 | error(errorCode, errorString); | - | ||||||||||||||||||
1328 | } executed 112 times by 4 tests: end of block Executed by:
| 112 | ||||||||||||||||||
1329 | - | |||||||||||||||||||
1330 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
1331 | void QNetworkReplyHttpImplPrivate::replyEncrypted() | - | ||||||||||||||||||
1332 | { | - | ||||||||||||||||||
1333 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
1334 | emit q->encrypted(); | - | ||||||||||||||||||
1335 | } executed 73 times by 2 tests: end of block Executed by:
| 73 | ||||||||||||||||||
1336 | - | |||||||||||||||||||
1337 | void QNetworkReplyHttpImplPrivate::replySslErrors( | - | ||||||||||||||||||
1338 | const QList<QSslError> &list, bool *ignoreAll, QList<QSslError> *toBeIgnored) | - | ||||||||||||||||||
1339 | { | - | ||||||||||||||||||
1340 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
1341 | emit q->sslErrors(list); | - | ||||||||||||||||||
1342 | // Check if the callback set any ignore and return this here to http thread | - | ||||||||||||||||||
1343 | if (pendingIgnoreAllSslErrors)
| 14-32 | ||||||||||||||||||
1344 | *ignoreAll = true; executed 32 times by 2 tests: *ignoreAll = true; Executed by:
| 32 | ||||||||||||||||||
1345 | if (!pendingIgnoreSslErrorsList.isEmpty())
| 6-40 | ||||||||||||||||||
1346 | *toBeIgnored = pendingIgnoreSslErrorsList; executed 6 times by 1 test: *toBeIgnored = pendingIgnoreSslErrorsList; Executed by:
| 6 | ||||||||||||||||||
1347 | } executed 46 times by 2 tests: end of block Executed by:
| 46 | ||||||||||||||||||
1348 | - | |||||||||||||||||||
1349 | void QNetworkReplyHttpImplPrivate::replySslConfigurationChanged(const QSslConfiguration &sslConfiguration) | - | ||||||||||||||||||
1350 | { | - | ||||||||||||||||||
1351 | // Receiving the used SSL configuration from the HTTP thread | - | ||||||||||||||||||
1352 | this->sslConfiguration = sslConfiguration; | - | ||||||||||||||||||
1353 | } executed 522 times by 2 tests: end of block Executed by:
| 522 | ||||||||||||||||||
1354 | - | |||||||||||||||||||
1355 | void QNetworkReplyHttpImplPrivate::replyPreSharedKeyAuthenticationRequiredSlot(QSslPreSharedKeyAuthenticator *authenticator) | - | ||||||||||||||||||
1356 | { | - | ||||||||||||||||||
1357 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
1358 | emit q->preSharedKeyAuthenticationRequired(authenticator); | - | ||||||||||||||||||
1359 | } never executed: end of block | 0 | ||||||||||||||||||
1360 | #endif | - | ||||||||||||||||||
1361 | - | |||||||||||||||||||
1362 | // Coming from QNonContiguousByteDeviceThreadForwardImpl in HTTP thread | - | ||||||||||||||||||
1363 | void QNetworkReplyHttpImplPrivate::resetUploadDataSlot(bool *r) | - | ||||||||||||||||||
1364 | { | - | ||||||||||||||||||
1365 | *r = uploadByteDevice->reset(); | - | ||||||||||||||||||
1366 | if (*r) {
| 1-126 | ||||||||||||||||||
1367 | // reset our own position which is used for the inter-thread communication | - | ||||||||||||||||||
1368 | uploadByteDevicePosition = 0; | - | ||||||||||||||||||
1369 | } executed 126 times by 1 test: end of block Executed by:
| 126 | ||||||||||||||||||
1370 | } executed 127 times by 1 test: end of block Executed by:
| 127 | ||||||||||||||||||
1371 | - | |||||||||||||||||||
1372 | // Coming from QNonContiguousByteDeviceThreadForwardImpl in HTTP thread | - | ||||||||||||||||||
1373 | void QNetworkReplyHttpImplPrivate::sentUploadDataSlot(qint64 pos, qint64 amount) | - | ||||||||||||||||||
1374 | { | - | ||||||||||||||||||
1375 | if (uploadByteDevicePosition + amount != pos) {
| 0-2695 | ||||||||||||||||||
1376 | // Sanity check, should not happen. | - | ||||||||||||||||||
1377 | error(QNetworkReply::UnknownNetworkError, QString()); | - | ||||||||||||||||||
1378 | return; never executed: return; | 0 | ||||||||||||||||||
1379 | } | - | ||||||||||||||||||
1380 | uploadByteDevice->advanceReadPointer(amount); | - | ||||||||||||||||||
1381 | uploadByteDevicePosition += amount; | - | ||||||||||||||||||
1382 | } executed 2695 times by 2 tests: end of block Executed by:
| 2695 | ||||||||||||||||||
1383 | - | |||||||||||||||||||
1384 | // Coming from QNonContiguousByteDeviceThreadForwardImpl in HTTP thread | - | ||||||||||||||||||
1385 | void QNetworkReplyHttpImplPrivate::wantUploadDataSlot(qint64 maxSize) | - | ||||||||||||||||||
1386 | { | - | ||||||||||||||||||
1387 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
1388 | - | |||||||||||||||||||
1389 | // call readPointer | - | ||||||||||||||||||
1390 | qint64 currentUploadDataLength = 0; | - | ||||||||||||||||||
1391 | char *data = const_cast<char*>(uploadByteDevice->readPointer(maxSize, currentUploadDataLength)); | - | ||||||||||||||||||
1392 | - | |||||||||||||||||||
1393 | if (currentUploadDataLength == 0) {
| 4-2710 | ||||||||||||||||||
1394 | uploadDeviceChoking = true; | - | ||||||||||||||||||
1395 | // No bytes from upload byte device. There will be bytes later, it will emit readyRead() | - | ||||||||||||||||||
1396 | // and our uploadByteDeviceReadyReadSlot() is called. | - | ||||||||||||||||||
1397 | return; executed 4 times by 1 test: return; Executed by:
| 4 | ||||||||||||||||||
1398 | } else { | - | ||||||||||||||||||
1399 | uploadDeviceChoking = false; | - | ||||||||||||||||||
1400 | } executed 2710 times by 3 tests: end of block Executed by:
| 2710 | ||||||||||||||||||
1401 | - | |||||||||||||||||||
1402 | // Let's make a copy of this data | - | ||||||||||||||||||
1403 | QByteArray dataArray(data, currentUploadDataLength); | - | ||||||||||||||||||
1404 | - | |||||||||||||||||||
1405 | // Communicate back to HTTP thread | - | ||||||||||||||||||
1406 | emit q->haveUploadData(uploadByteDevicePosition, dataArray, uploadByteDevice->atEnd(), uploadByteDevice->size()); | - | ||||||||||||||||||
1407 | } executed 2710 times by 3 tests: end of block Executed by:
| 2710 | ||||||||||||||||||
1408 | - | |||||||||||||||||||
1409 | void QNetworkReplyHttpImplPrivate::uploadByteDeviceReadyReadSlot() | - | ||||||||||||||||||
1410 | { | - | ||||||||||||||||||
1411 | // Start the flow between this thread and the HTTP thread again by triggering a upload. | - | ||||||||||||||||||
1412 | // However only do this when we were choking before, else the state in | - | ||||||||||||||||||
1413 | // QNonContiguousByteDeviceThreadForwardImpl gets messed up. | - | ||||||||||||||||||
1414 | if (uploadDeviceChoking) {
| 4-6 | ||||||||||||||||||
1415 | uploadDeviceChoking = false; | - | ||||||||||||||||||
1416 | wantUploadDataSlot(1024); | - | ||||||||||||||||||
1417 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
1418 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||
1419 | - | |||||||||||||||||||
1420 | - | |||||||||||||||||||
1421 | /* | - | ||||||||||||||||||
1422 | A simple web page that can be used to test us: http://www.procata.com/cachetest/ | - | ||||||||||||||||||
1423 | */ | - | ||||||||||||||||||
1424 | bool QNetworkReplyHttpImplPrivate::sendCacheContents(const QNetworkCacheMetaData &metaData) | - | ||||||||||||||||||
1425 | { | - | ||||||||||||||||||
1426 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
1427 | - | |||||||||||||||||||
1428 | setCachingEnabled(false); | - | ||||||||||||||||||
1429 | if (!metaData.isValid())
| 0-27 | ||||||||||||||||||
1430 | return false; never executed: return false; | 0 | ||||||||||||||||||
1431 | - | |||||||||||||||||||
1432 | QAbstractNetworkCache *nc = managerPrivate->networkCache; | - | ||||||||||||||||||
1433 | Q_ASSERT(nc); | - | ||||||||||||||||||
1434 | QIODevice *contents = nc->data(url); | - | ||||||||||||||||||
1435 | if (!contents) {
| 0-27 | ||||||||||||||||||
1436 | #if defined(QNETWORKACCESSHTTPBACKEND_DEBUG) | - | ||||||||||||||||||
1437 | qDebug() << "Can not send cache, the contents are 0" << url; | - | ||||||||||||||||||
1438 | #endif | - | ||||||||||||||||||
1439 | return false; never executed: return false; | 0 | ||||||||||||||||||
1440 | } | - | ||||||||||||||||||
1441 | contents->setParent(q); | - | ||||||||||||||||||
1442 | - | |||||||||||||||||||
1443 | QNetworkCacheMetaData::AttributesMap attributes = metaData.attributes(); | - | ||||||||||||||||||
1444 | int status = attributes.value(QNetworkRequest::HttpStatusCodeAttribute).toInt(); | - | ||||||||||||||||||
1445 | if (status < 100)
| 8-19 | ||||||||||||||||||
1446 | status = 200; // fake it executed 8 times by 1 test: status = 200; Executed by:
| 8 | ||||||||||||||||||
1447 | - | |||||||||||||||||||
1448 | statusCode = status; | - | ||||||||||||||||||
1449 | - | |||||||||||||||||||
1450 | q->setAttribute(QNetworkRequest::HttpStatusCodeAttribute, status); | - | ||||||||||||||||||
1451 | q->setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, attributes.value(QNetworkRequest::HttpReasonPhraseAttribute)); | - | ||||||||||||||||||
1452 | q->setAttribute(QNetworkRequest::SourceIsFromCacheAttribute, true); | - | ||||||||||||||||||
1453 | - | |||||||||||||||||||
1454 | QNetworkCacheMetaData::RawHeaderList rawHeaders = metaData.rawHeaders(); | - | ||||||||||||||||||
1455 | QNetworkCacheMetaData::RawHeaderList::ConstIterator it = rawHeaders.constBegin(), | - | ||||||||||||||||||
1456 | end = rawHeaders.constEnd(); | - | ||||||||||||||||||
1457 | QUrl redirectUrl; | - | ||||||||||||||||||
1458 | for ( ; it != end; ++it) {
| 27-100 | ||||||||||||||||||
1459 | if (httpRequest.isFollowRedirects() &&
| 0-100 | ||||||||||||||||||
1460 | !qstricmp(it->first.toLower().constData(), "location"))
| 0 | ||||||||||||||||||
1461 | redirectUrl = QUrl::fromEncoded(it->second); never executed: redirectUrl = QUrl::fromEncoded(it->second); | 0 | ||||||||||||||||||
1462 | setRawHeader(it->first, it->second); | - | ||||||||||||||||||
1463 | } executed 100 times by 2 tests: end of block Executed by:
| 100 | ||||||||||||||||||
1464 | - | |||||||||||||||||||
1465 | if (!isHttpRedirectResponse())
| 0-27 | ||||||||||||||||||
1466 | checkForRedirect(status); executed 27 times by 2 tests: checkForRedirect(status); Executed by:
| 27 | ||||||||||||||||||
1467 | - | |||||||||||||||||||
1468 | cacheLoadDevice = contents; | - | ||||||||||||||||||
1469 | q->connect(cacheLoadDevice, SIGNAL(readyRead()), SLOT(_q_cacheLoadReadyRead())); | - | ||||||||||||||||||
1470 | q->connect(cacheLoadDevice, SIGNAL(readChannelFinished()), SLOT(_q_cacheLoadReadyRead())); | - | ||||||||||||||||||
1471 | - | |||||||||||||||||||
1472 | // This needs to be emitted in the event loop because it can be reached at | - | ||||||||||||||||||
1473 | // the direct code path of qnam.get(...) before the user has a chance | - | ||||||||||||||||||
1474 | // to connect any signals. | - | ||||||||||||||||||
1475 | QMetaObject::invokeMethod(q, "_q_metaDataChanged", Qt::QueuedConnection); | - | ||||||||||||||||||
1476 | QMetaObject::invokeMethod(q, "_q_cacheLoadReadyRead", Qt::QueuedConnection); | - | ||||||||||||||||||
1477 | - | |||||||||||||||||||
1478 | - | |||||||||||||||||||
1479 | #if defined(QNETWORKACCESSHTTPBACKEND_DEBUG) | - | ||||||||||||||||||
1480 | qDebug() << "Successfully sent cache:" << url << contents->size() << "bytes"; | - | ||||||||||||||||||
1481 | #endif | - | ||||||||||||||||||
1482 | - | |||||||||||||||||||
1483 | // Do redirect processing | - | ||||||||||||||||||
1484 | if (httpRequest.isFollowRedirects() && QHttpNetworkReply::isHttpRedirect(status)) {
| 0-27 | ||||||||||||||||||
1485 | QMetaObject::invokeMethod(q, "onRedirected", Qt::QueuedConnection, | - | ||||||||||||||||||
1486 | Q_ARG(QUrl, redirectUrl), | - | ||||||||||||||||||
1487 | Q_ARG(int, status), | - | ||||||||||||||||||
1488 | Q_ARG(int, httpRequest.redirectCount() - 1)); | - | ||||||||||||||||||
1489 | } never executed: end of block | 0 | ||||||||||||||||||
1490 | - | |||||||||||||||||||
1491 | // Set the following flag so we can ignore some signals from HTTP thread | - | ||||||||||||||||||
1492 | // that would still come | - | ||||||||||||||||||
1493 | loadingFromCache = true; | - | ||||||||||||||||||
1494 | return true; executed 27 times by 2 tests: return true; Executed by:
| 27 | ||||||||||||||||||
1495 | } | - | ||||||||||||||||||
1496 | - | |||||||||||||||||||
1497 | QNetworkCacheMetaData QNetworkReplyHttpImplPrivate::fetchCacheMetaData(const QNetworkCacheMetaData &oldMetaData) const | - | ||||||||||||||||||
1498 | { | - | ||||||||||||||||||
1499 | Q_Q(const QNetworkReplyHttpImpl); | - | ||||||||||||||||||
1500 | - | |||||||||||||||||||
1501 | QNetworkCacheMetaData metaData = oldMetaData; | - | ||||||||||||||||||
1502 | - | |||||||||||||||||||
1503 | QNetworkHeadersPrivate cacheHeaders; | - | ||||||||||||||||||
1504 | cacheHeaders.setAllRawHeaders(metaData.rawHeaders()); | - | ||||||||||||||||||
1505 | QNetworkHeadersPrivate::RawHeadersList::ConstIterator it; | - | ||||||||||||||||||
1506 | - | |||||||||||||||||||
1507 | QList<QByteArray> newHeaders = q->rawHeaderList(); | - | ||||||||||||||||||
1508 | foreach (QByteArray header, newHeaders) { | - | ||||||||||||||||||
1509 | QByteArray originalHeader = header; | - | ||||||||||||||||||
1510 | header = header.toLower(); | - | ||||||||||||||||||
1511 | bool hop_by_hop = | - | ||||||||||||||||||
1512 | (header == "connection"
| 69-387 | ||||||||||||||||||
1513 | || header == "keep-alive"
| 62-325 | ||||||||||||||||||
1514 | || header == "proxy-authenticate"
| 0-325 | ||||||||||||||||||
1515 | || header == "proxy-authorization"
| 0-325 | ||||||||||||||||||
1516 | || header == "te"
| 0-325 | ||||||||||||||||||
1517 | || header == "trailers"
| 0-325 | ||||||||||||||||||
1518 | || header == "transfer-encoding"
| 41-284 | ||||||||||||||||||
1519 | || header == "upgrade");
| 0-284 | ||||||||||||||||||
1520 | if (hop_by_hop)
| 172-284 | ||||||||||||||||||
1521 | continue; executed 172 times by 2 tests: continue; Executed by:
| 172 | ||||||||||||||||||
1522 | - | |||||||||||||||||||
1523 | if (header == "set-cookie")
| 0-284 | ||||||||||||||||||
1524 | continue; never executed: continue; | 0 | ||||||||||||||||||
1525 | - | |||||||||||||||||||
1526 | // for 4.6.0, we were planning to not store the date header in the | - | ||||||||||||||||||
1527 | // cached resource; through that we planned to reduce the number | - | ||||||||||||||||||
1528 | // of writes to disk when using a QNetworkDiskCache (i.e. don't | - | ||||||||||||||||||
1529 | // write to disk when only the date changes). | - | ||||||||||||||||||
1530 | // However, without the date we cannot calculate the age of the page | - | ||||||||||||||||||
1531 | // anymore. | - | ||||||||||||||||||
1532 | //if (header == "date") | - | ||||||||||||||||||
1533 | //continue; | - | ||||||||||||||||||
1534 | - | |||||||||||||||||||
1535 | // Don't store Warning 1xx headers | - | ||||||||||||||||||
1536 | if (header == "warning") {
| 0-284 | ||||||||||||||||||
1537 | QByteArray v = q->rawHeader(header); | - | ||||||||||||||||||
1538 | if (v.length() == 3
| 0 | ||||||||||||||||||
1539 | && v[0] == '1'
| 0 | ||||||||||||||||||
1540 | && v[1] >= '0' && v[1] <= '9'
| 0 | ||||||||||||||||||
1541 | && v[2] >= '0' && v[2] <= '9')
| 0 | ||||||||||||||||||
1542 | continue; never executed: continue; | 0 | ||||||||||||||||||
1543 | } never executed: end of block | 0 | ||||||||||||||||||
1544 | - | |||||||||||||||||||
1545 | it = cacheHeaders.findRawHeader(header); | - | ||||||||||||||||||
1546 | if (it != cacheHeaders.rawHeaders.constEnd()) {
| 13-271 | ||||||||||||||||||
1547 | // Match the behavior of Firefox and assume Cache-Control: "no-transform" | - | ||||||||||||||||||
1548 | if (header == "content-encoding"
| 0-13 | ||||||||||||||||||
1549 | || header == "content-range"
| 0-13 | ||||||||||||||||||
1550 | || header == "content-type")
| 0-13 | ||||||||||||||||||
1551 | continue; never executed: continue; | 0 | ||||||||||||||||||
1552 | - | |||||||||||||||||||
1553 | // For MS servers that send "Content-Length: 0" on 304 responses | - | ||||||||||||||||||
1554 | // ignore this too | - | ||||||||||||||||||
1555 | if (header == "content-length")
| 0-13 | ||||||||||||||||||
1556 | continue; never executed: continue; | 0 | ||||||||||||||||||
1557 | } executed 13 times by 1 test: end of block Executed by:
| 13 | ||||||||||||||||||
1558 | - | |||||||||||||||||||
1559 | #if defined(QNETWORKACCESSHTTPBACKEND_DEBUG) | - | ||||||||||||||||||
1560 | QByteArray n = q->rawHeader(header); | - | ||||||||||||||||||
1561 | QByteArray o; | - | ||||||||||||||||||
1562 | if (it != cacheHeaders.rawHeaders.constEnd()) | - | ||||||||||||||||||
1563 | o = (*it).second; | - | ||||||||||||||||||
1564 | if (n != o && header != "date") { | - | ||||||||||||||||||
1565 | qDebug() << "replacing" << header; | - | ||||||||||||||||||
1566 | qDebug() << "new" << n; | - | ||||||||||||||||||
1567 | qDebug() << "old" << o; | - | ||||||||||||||||||
1568 | } | - | ||||||||||||||||||
1569 | #endif | - | ||||||||||||||||||
1570 | cacheHeaders.setRawHeader(originalHeader, q->rawHeader(header)); | - | ||||||||||||||||||
1571 | } executed 284 times by 3 tests: end of block Executed by:
| 284 | ||||||||||||||||||
1572 | metaData.setRawHeaders(cacheHeaders.rawHeaders); | - | ||||||||||||||||||
1573 | - | |||||||||||||||||||
1574 | bool checkExpired = true; | - | ||||||||||||||||||
1575 | - | |||||||||||||||||||
1576 | QHash<QByteArray, QByteArray> cacheControl; | - | ||||||||||||||||||
1577 | it = cacheHeaders.findRawHeader("Cache-Control"); | - | ||||||||||||||||||
1578 | if (it != cacheHeaders.rawHeaders.constEnd()) {
| 28-42 | ||||||||||||||||||
1579 | cacheControl = parseHttpOptionHeader(it->second); | - | ||||||||||||||||||
1580 | QByteArray maxAge = cacheControl.value("max-age"); | - | ||||||||||||||||||
1581 | if (!maxAge.isEmpty()) {
| 7-21 | ||||||||||||||||||
1582 | checkExpired = false; | - | ||||||||||||||||||
1583 | QDateTime dt = QDateTime::currentDateTimeUtc(); | - | ||||||||||||||||||
1584 | dt = dt.addSecs(maxAge.toInt()); | - | ||||||||||||||||||
1585 | metaData.setExpirationDate(dt); | - | ||||||||||||||||||
1586 | } executed 21 times by 2 tests: end of block Executed by:
| 21 | ||||||||||||||||||
1587 | } executed 28 times by 2 tests: end of block Executed by:
| 28 | ||||||||||||||||||
1588 | if (checkExpired) {
| 21-49 | ||||||||||||||||||
1589 | it = cacheHeaders.findRawHeader("expires"); | - | ||||||||||||||||||
1590 | if (it != cacheHeaders.rawHeaders.constEnd()) {
| 17-32 | ||||||||||||||||||
1591 | QDateTime expiredDateTime = QNetworkHeadersPrivate::fromHttpDate(it->second); | - | ||||||||||||||||||
1592 | metaData.setExpirationDate(expiredDateTime); | - | ||||||||||||||||||
1593 | } executed 17 times by 1 test: end of block Executed by:
| 17 | ||||||||||||||||||
1594 | } executed 49 times by 2 tests: end of block Executed by:
| 49 | ||||||||||||||||||
1595 | - | |||||||||||||||||||
1596 | it = cacheHeaders.findRawHeader("last-modified"); | - | ||||||||||||||||||
1597 | if (it != cacheHeaders.rawHeaders.constEnd())
| 29-41 | ||||||||||||||||||
1598 | metaData.setLastModified(QNetworkHeadersPrivate::fromHttpDate(it->second)); executed 29 times by 1 test: metaData.setLastModified(QNetworkHeadersPrivate::fromHttpDate(it->second)); Executed by:
| 29 | ||||||||||||||||||
1599 | - | |||||||||||||||||||
1600 | bool canDiskCache; | - | ||||||||||||||||||
1601 | // only cache GET replies by default, all other replies (POST, PUT, DELETE) | - | ||||||||||||||||||
1602 | // are not cacheable by default (according to RFC 2616 section 9) | - | ||||||||||||||||||
1603 | if (httpRequest.operation() == QHttpNetworkRequest::Get) {
| 0-70 | ||||||||||||||||||
1604 | - | |||||||||||||||||||
1605 | canDiskCache = true; | - | ||||||||||||||||||
1606 | // 14.32 | - | ||||||||||||||||||
1607 | // HTTP/1.1 caches SHOULD treat "Pragma: no-cache" as if the client | - | ||||||||||||||||||
1608 | // had sent "Cache-Control: no-cache". | - | ||||||||||||||||||
1609 | it = cacheHeaders.findRawHeader("pragma"); | - | ||||||||||||||||||
1610 | if (it != cacheHeaders.rawHeaders.constEnd()
| 0-70 | ||||||||||||||||||
1611 | && it->second == "no-cache")
| 0 | ||||||||||||||||||
1612 | canDiskCache = false; never executed: canDiskCache = false; | 0 | ||||||||||||||||||
1613 | - | |||||||||||||||||||
1614 | // HTTP/1.1. Check the Cache-Control header | - | ||||||||||||||||||
1615 | if (cacheControl.contains("no-cache"))
| 7-63 | ||||||||||||||||||
1616 | canDiskCache = false; executed 7 times by 1 test: canDiskCache = false; Executed by:
| 7 | ||||||||||||||||||
1617 | else if (cacheControl.contains("no-store"))
| 0-63 | ||||||||||||||||||
1618 | canDiskCache = false; never executed: canDiskCache = false; | 0 | ||||||||||||||||||
1619 | - | |||||||||||||||||||
1620 | // responses to POST might be cacheable | - | ||||||||||||||||||
1621 | } else if (httpRequest.operation() == QHttpNetworkRequest::Post) { executed 70 times by 3 tests: end of block Executed by:
| 0-70 | ||||||||||||||||||
1622 | - | |||||||||||||||||||
1623 | canDiskCache = false; | - | ||||||||||||||||||
1624 | // some pages contain "expires:" and "cache-control: no-cache" field, | - | ||||||||||||||||||
1625 | // so we only might cache POST requests if we get "cache-control: max-age ..." | - | ||||||||||||||||||
1626 | if (cacheControl.contains("max-age"))
| 0 | ||||||||||||||||||
1627 | canDiskCache = true; never executed: canDiskCache = true; | 0 | ||||||||||||||||||
1628 | - | |||||||||||||||||||
1629 | // responses to PUT and DELETE are not cacheable | - | ||||||||||||||||||
1630 | } else { never executed: end of block | 0 | ||||||||||||||||||
1631 | canDiskCache = false; | - | ||||||||||||||||||
1632 | } never executed: end of block | 0 | ||||||||||||||||||
1633 | - | |||||||||||||||||||
1634 | metaData.setSaveToDisk(canDiskCache); | - | ||||||||||||||||||
1635 | QNetworkCacheMetaData::AttributesMap attributes; | - | ||||||||||||||||||
1636 | if (statusCode != 304) {
| 9-61 | ||||||||||||||||||
1637 | // update the status code | - | ||||||||||||||||||
1638 | attributes.insert(QNetworkRequest::HttpStatusCodeAttribute, statusCode); | - | ||||||||||||||||||
1639 | attributes.insert(QNetworkRequest::HttpReasonPhraseAttribute, reasonPhrase); | - | ||||||||||||||||||
1640 | } else { executed 61 times by 3 tests: end of block Executed by:
| 61 | ||||||||||||||||||
1641 | // this is a redirection, keep the attributes intact | - | ||||||||||||||||||
1642 | attributes = oldMetaData.attributes(); | - | ||||||||||||||||||
1643 | } executed 9 times by 2 tests: end of block Executed by:
| 9 | ||||||||||||||||||
1644 | metaData.setAttributes(attributes); | - | ||||||||||||||||||
1645 | return metaData; executed 70 times by 3 tests: return metaData; Executed by:
| 70 | ||||||||||||||||||
1646 | } | - | ||||||||||||||||||
1647 | - | |||||||||||||||||||
1648 | bool QNetworkReplyHttpImplPrivate::canResume() const | - | ||||||||||||||||||
1649 | { | - | ||||||||||||||||||
1650 | Q_Q(const QNetworkReplyHttpImpl); | - | ||||||||||||||||||
1651 | - | |||||||||||||||||||
1652 | // Only GET operation supports resuming. | - | ||||||||||||||||||
1653 | if (operation != QNetworkAccessManager::GetOperation)
| 0 | ||||||||||||||||||
1654 | return false; never executed: return false; | 0 | ||||||||||||||||||
1655 | - | |||||||||||||||||||
1656 | // Can only resume if server/resource supports Range header. | - | ||||||||||||||||||
1657 | QByteArray acceptRangesheaderName("Accept-Ranges"); | - | ||||||||||||||||||
1658 | if (!q->hasRawHeader(acceptRangesheaderName) || q->rawHeader(acceptRangesheaderName) == "none")
| 0 | ||||||||||||||||||
1659 | return false; never executed: return false; | 0 | ||||||||||||||||||
1660 | - | |||||||||||||||||||
1661 | // We only support resuming for byte ranges. | - | ||||||||||||||||||
1662 | if (request.hasRawHeader("Range")) {
| 0 | ||||||||||||||||||
1663 | QByteArray range = request.rawHeader("Range"); | - | ||||||||||||||||||
1664 | if (!range.startsWith("bytes="))
| 0 | ||||||||||||||||||
1665 | return false; never executed: return false; | 0 | ||||||||||||||||||
1666 | } never executed: end of block | 0 | ||||||||||||||||||
1667 | - | |||||||||||||||||||
1668 | // If we're using a download buffer then we don't support resuming/migration | - | ||||||||||||||||||
1669 | // right now. Too much trouble. | - | ||||||||||||||||||
1670 | if (downloadZerocopyBuffer)
| 0 | ||||||||||||||||||
1671 | return false; never executed: return false; | 0 | ||||||||||||||||||
1672 | - | |||||||||||||||||||
1673 | return true; never executed: return true; | 0 | ||||||||||||||||||
1674 | } | - | ||||||||||||||||||
1675 | - | |||||||||||||||||||
1676 | void QNetworkReplyHttpImplPrivate::setResumeOffset(quint64 offset) | - | ||||||||||||||||||
1677 | { | - | ||||||||||||||||||
1678 | resumeOffset = offset; | - | ||||||||||||||||||
1679 | } never executed: end of block | 0 | ||||||||||||||||||
1680 | - | |||||||||||||||||||
1681 | /*! | - | ||||||||||||||||||
1682 | Starts the backend. Returns \c true if the backend is started. Returns \c false if the backend | - | ||||||||||||||||||
1683 | could not be started due to an unopened or roaming session. The caller should recall this | - | ||||||||||||||||||
1684 | function once the session has been opened or the roaming process has finished. | - | ||||||||||||||||||
1685 | */ | - | ||||||||||||||||||
1686 | bool QNetworkReplyHttpImplPrivate::start(const QNetworkRequest &newHttpRequest) | - | ||||||||||||||||||
1687 | { | - | ||||||||||||||||||
1688 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
1689 | QSharedPointer<QNetworkSession> networkSession(managerPrivate->getNetworkSession()); | - | ||||||||||||||||||
1690 | if (!networkSession) {
| 0-946 | ||||||||||||||||||
1691 | #endif | - | ||||||||||||||||||
1692 | postRequest(newHttpRequest); | - | ||||||||||||||||||
1693 | return true; never executed: return true; | 0 | ||||||||||||||||||
1694 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
1695 | } | - | ||||||||||||||||||
1696 | - | |||||||||||||||||||
1697 | // This is not ideal. | - | ||||||||||||||||||
1698 | const QString host = url.host(); | - | ||||||||||||||||||
1699 | if (host == QLatin1String("localhost") ||
| 138-808 | ||||||||||||||||||
1700 | QHostAddress(host).isLoopback()) {
| 43-765 | ||||||||||||||||||
1701 | // Don't need an open session for localhost access. | - | ||||||||||||||||||
1702 | postRequest(newHttpRequest); | - | ||||||||||||||||||
1703 | return true; executed 181 times by 4 tests: return true; Executed by:
| 181 | ||||||||||||||||||
1704 | } | - | ||||||||||||||||||
1705 | - | |||||||||||||||||||
1706 | if (networkSession->isOpen() &&
| 56-709 | ||||||||||||||||||
1707 | networkSession->state() == QNetworkSession::Connected) {
| 0-709 | ||||||||||||||||||
1708 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
1709 | QObject::connect(networkSession.data(), SIGNAL(usagePoliciesChanged(QNetworkSession::UsagePolicies)), | - | ||||||||||||||||||
1710 | q, SLOT(_q_networkSessionUsagePoliciesChanged(QNetworkSession::UsagePolicies))); | - | ||||||||||||||||||
1711 | postRequest(newHttpRequest); | - | ||||||||||||||||||
1712 | return true; executed 709 times by 5 tests: return true; Executed by:
| 709 | ||||||||||||||||||
1713 | } else if (synchronous) {
| 0-56 | ||||||||||||||||||
1714 | // Command line applications using the synchronous path such as xmlpatterns may need an extra push. | - | ||||||||||||||||||
1715 | networkSession->open(); | - | ||||||||||||||||||
1716 | if (networkSession->waitForOpened()) {
| 0 | ||||||||||||||||||
1717 | postRequest(newHttpRequest); | - | ||||||||||||||||||
1718 | return true; never executed: return true; | 0 | ||||||||||||||||||
1719 | } | - | ||||||||||||||||||
1720 | } never executed: end of block | 0 | ||||||||||||||||||
1721 | return false; executed 56 times by 5 tests: return false; Executed by:
| 56 | ||||||||||||||||||
1722 | #endif | - | ||||||||||||||||||
1723 | } | - | ||||||||||||||||||
1724 | - | |||||||||||||||||||
1725 | void QNetworkReplyHttpImplPrivate::_q_startOperation() | - | ||||||||||||||||||
1726 | { | - | ||||||||||||||||||
1727 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
1728 | - | |||||||||||||||||||
1729 | // ensure this function is only being called once | - | ||||||||||||||||||
1730 | if (state == Working) {
| 0-943 | ||||||||||||||||||
1731 | qDebug("QNetworkReplyImpl::_q_startOperation was called more than once"); | - | ||||||||||||||||||
1732 | return; never executed: return; | 0 | ||||||||||||||||||
1733 | } | - | ||||||||||||||||||
1734 | state = Working; | - | ||||||||||||||||||
1735 | - | |||||||||||||||||||
1736 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
1737 | // Do not start background requests if they are not allowed by session policy | - | ||||||||||||||||||
1738 | QSharedPointer<QNetworkSession> session(manager->d_func()->getNetworkSession()); | - | ||||||||||||||||||
1739 | QVariant isBackground = request.attribute(QNetworkRequest::BackgroundRequestAttribute, QVariant::fromValue(false)); | - | ||||||||||||||||||
1740 | if (isBackground.toBool() && session && session->usagePolicies().testFlag(QNetworkSession::NoBackgroundTrafficPolicy)) {
| 0-935 | ||||||||||||||||||
1741 | QMetaObject::invokeMethod(q, "_q_error", synchronous ? Qt::DirectConnection : Qt::QueuedConnection, | - | ||||||||||||||||||
1742 | Q_ARG(QNetworkReply::NetworkError, QNetworkReply::BackgroundRequestNotAllowedError), | - | ||||||||||||||||||
1743 | Q_ARG(QString, QCoreApplication::translate("QNetworkReply", "Background request not allowed."))); | - | ||||||||||||||||||
1744 | QMetaObject::invokeMethod(q, "_q_finished", synchronous ? Qt::DirectConnection : Qt::QueuedConnection); | - | ||||||||||||||||||
1745 | return; executed 2 times by 1 test: return; Executed by:
| 2 | ||||||||||||||||||
1746 | } | - | ||||||||||||||||||
1747 | - | |||||||||||||||||||
1748 | if (!start(request)) {
| 56-885 | ||||||||||||||||||
1749 | // backend failed to start because the session state is not Connected. | - | ||||||||||||||||||
1750 | // QNetworkAccessManager will call reply->backend->start() again for us when the session | - | ||||||||||||||||||
1751 | // state changes. | - | ||||||||||||||||||
1752 | state = WaitingForSession; | - | ||||||||||||||||||
1753 | - | |||||||||||||||||||
1754 | if (session) {
| 0-56 | ||||||||||||||||||
1755 | QObject::connect(session.data(), SIGNAL(error(QNetworkSession::SessionError)), | - | ||||||||||||||||||
1756 | q, SLOT(_q_networkSessionFailed()), Qt::QueuedConnection); | - | ||||||||||||||||||
1757 | - | |||||||||||||||||||
1758 | if (!session->isOpen()) {
| 0-56 | ||||||||||||||||||
1759 | session->setSessionProperty(QStringLiteral("ConnectInBackground"), isBackground); executed 56 times by 5 tests: return qstring_literal_temp; Executed by:
| 56 | ||||||||||||||||||
1760 | session->open(); | - | ||||||||||||||||||
1761 | } executed 56 times by 5 tests: end of block Executed by:
| 56 | ||||||||||||||||||
1762 | } else { executed 56 times by 5 tests: end of block Executed by:
| 56 | ||||||||||||||||||
1763 | qWarning("Backend is waiting for QNetworkSession to connect, but there is none!"); | - | ||||||||||||||||||
1764 | QMetaObject::invokeMethod(q, "_q_error", synchronous ? Qt::DirectConnection : Qt::QueuedConnection, | - | ||||||||||||||||||
1765 | Q_ARG(QNetworkReply::NetworkError, QNetworkReply::NetworkSessionFailedError), | - | ||||||||||||||||||
1766 | Q_ARG(QString, QCoreApplication::translate("QNetworkReply", "Network session error."))); | - | ||||||||||||||||||
1767 | QMetaObject::invokeMethod(q, "_q_finished", synchronous ? Qt::DirectConnection : Qt::QueuedConnection); | - | ||||||||||||||||||
1768 | return; never executed: return; | 0 | ||||||||||||||||||
1769 | } | - | ||||||||||||||||||
1770 | } else if (session) {
| 0-885 | ||||||||||||||||||
1771 | QObject::connect(session.data(), SIGNAL(stateChanged(QNetworkSession::State)), | - | ||||||||||||||||||
1772 | q, SLOT(_q_networkSessionStateChanged(QNetworkSession::State)), | - | ||||||||||||||||||
1773 | Qt::QueuedConnection); | - | ||||||||||||||||||
1774 | } executed 885 times by 8 tests: end of block Executed by:
| 885 | ||||||||||||||||||
1775 | #else | - | ||||||||||||||||||
1776 | if (!start(request)) { | - | ||||||||||||||||||
1777 | qWarning("Backend start failed"); | - | ||||||||||||||||||
1778 | QMetaObject::invokeMethod(q, "_q_error", synchronous ? Qt::DirectConnection : Qt::QueuedConnection, | - | ||||||||||||||||||
1779 | Q_ARG(QNetworkReply::NetworkError, QNetworkReply::UnknownNetworkError), | - | ||||||||||||||||||
1780 | Q_ARG(QString, QCoreApplication::translate("QNetworkReply", "backend start error."))); | - | ||||||||||||||||||
1781 | QMetaObject::invokeMethod(q, "_q_finished", synchronous ? Qt::DirectConnection : Qt::QueuedConnection); | - | ||||||||||||||||||
1782 | return; | - | ||||||||||||||||||
1783 | } | - | ||||||||||||||||||
1784 | #endif // QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
1785 | - | |||||||||||||||||||
1786 | if (synchronous) {
| 76-865 | ||||||||||||||||||
1787 | state = Finished; | - | ||||||||||||||||||
1788 | q_func()->setFinished(true); | - | ||||||||||||||||||
1789 | } executed 76 times by 1 test: end of block Executed by:
| 76 | ||||||||||||||||||
1790 | } executed 941 times by 8 tests: end of block Executed by:
| 941 | ||||||||||||||||||
1791 | - | |||||||||||||||||||
1792 | void QNetworkReplyHttpImplPrivate::_q_cacheLoadReadyRead() | - | ||||||||||||||||||
1793 | { | - | ||||||||||||||||||
1794 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
1795 | - | |||||||||||||||||||
1796 | if (state != Working)
| 0-27 | ||||||||||||||||||
1797 | return; never executed: return; | 0 | ||||||||||||||||||
1798 | if (!cacheLoadDevice || !q->isOpen() || !cacheLoadDevice->bytesAvailable())
| 0-27 | ||||||||||||||||||
1799 | return; never executed: return; | 0 | ||||||||||||||||||
1800 | - | |||||||||||||||||||
1801 | // FIXME Optimize to use zerocopy download buffer if it is a QBuffer. | - | ||||||||||||||||||
1802 | // Needs to be done where sendCacheContents() (?) of HTTP is emitting | - | ||||||||||||||||||
1803 | // metaDataChanged ? | - | ||||||||||||||||||
1804 | - | |||||||||||||||||||
1805 | - | |||||||||||||||||||
1806 | QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); | - | ||||||||||||||||||
1807 | - | |||||||||||||||||||
1808 | // emit readyRead before downloadProgress incase this will cause events to be | - | ||||||||||||||||||
1809 | // processed and we get into a recursive call (as in QProgressDialog). | - | ||||||||||||||||||
1810 | - | |||||||||||||||||||
1811 | if (!(isHttpRedirectResponse())) {
| 0-27 | ||||||||||||||||||
1812 | // This readyRead() goes to the user. The user then may or may not read() anything. | - | ||||||||||||||||||
1813 | emit q->readyRead(); | - | ||||||||||||||||||
1814 | - | |||||||||||||||||||
1815 | if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval) {
| 0-27 | ||||||||||||||||||
1816 | downloadProgressSignalChoke.restart(); | - | ||||||||||||||||||
1817 | emit q->downloadProgress(bytesDownloaded, | - | ||||||||||||||||||
1818 | totalSize.isNull() ? Q_INT64_C(-1) : totalSize.toLongLong()); | - | ||||||||||||||||||
1819 | } never executed: end of block | 0 | ||||||||||||||||||
1820 | } executed 27 times by 2 tests: end of block Executed by:
| 27 | ||||||||||||||||||
1821 | // If there are still bytes available in the cacheLoadDevice then the user did not read | - | ||||||||||||||||||
1822 | // in response to the readyRead() signal. This means we have to load from the cacheLoadDevice | - | ||||||||||||||||||
1823 | // and buffer that stuff. This is needed to be able to properly emit finished() later. | - | ||||||||||||||||||
1824 | while (cacheLoadDevice->bytesAvailable() && !isHttpRedirectResponse()) {
| 0-27 | ||||||||||||||||||
1825 | downloadMultiBuffer.append(cacheLoadDevice->readAll()); | - | ||||||||||||||||||
1826 | } executed 27 times by 2 tests: end of block Executed by:
| 27 | ||||||||||||||||||
1827 | - | |||||||||||||||||||
1828 | if (cacheLoadDevice->isSequential()) {
| 0-27 | ||||||||||||||||||
1829 | // check if end and we can read the EOF -1 | - | ||||||||||||||||||
1830 | char c; | - | ||||||||||||||||||
1831 | qint64 actualCount = cacheLoadDevice->read(&c, 1); | - | ||||||||||||||||||
1832 | if (actualCount < 0) {
| 0 | ||||||||||||||||||
1833 | cacheLoadDevice->deleteLater(); | - | ||||||||||||||||||
1834 | cacheLoadDevice = 0; | - | ||||||||||||||||||
1835 | QMetaObject::invokeMethod(q, "_q_finished", Qt::QueuedConnection); | - | ||||||||||||||||||
1836 | } else if (actualCount == 1) { never executed: end of block
| 0 | ||||||||||||||||||
1837 | // This is most probably not happening since most QIODevice returned something proper for bytesAvailable() | - | ||||||||||||||||||
1838 | // and had already been "emptied". | - | ||||||||||||||||||
1839 | cacheLoadDevice->ungetChar(c); | - | ||||||||||||||||||
1840 | } never executed: end of block | 0 | ||||||||||||||||||
1841 | } else if ((!cacheLoadDevice->isSequential() && cacheLoadDevice->atEnd())) { never executed: end of block
| 0-27 | ||||||||||||||||||
1842 | // This codepath is in case the cache device is a QBuffer, e.g. from QNetworkDiskCache. | - | ||||||||||||||||||
1843 | cacheLoadDevice->deleteLater(); | - | ||||||||||||||||||
1844 | cacheLoadDevice = 0; | - | ||||||||||||||||||
1845 | QMetaObject::invokeMethod(q, "_q_finished", Qt::QueuedConnection); | - | ||||||||||||||||||
1846 | } executed 27 times by 2 tests: end of block Executed by:
| 27 | ||||||||||||||||||
1847 | } executed 27 times by 2 tests: end of block Executed by:
| 27 | ||||||||||||||||||
1848 | - | |||||||||||||||||||
1849 | - | |||||||||||||||||||
1850 | void QNetworkReplyHttpImplPrivate::_q_bufferOutgoingDataFinished() | - | ||||||||||||||||||
1851 | { | - | ||||||||||||||||||
1852 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
1853 | - | |||||||||||||||||||
1854 | // make sure this is only called once, ever. | - | ||||||||||||||||||
1855 | //_q_bufferOutgoingData may call it or the readChannelFinished emission | - | ||||||||||||||||||
1856 | if (state != Buffering)
| 0-58 | ||||||||||||||||||
1857 | return; never executed: return; | 0 | ||||||||||||||||||
1858 | - | |||||||||||||||||||
1859 | // disconnect signals | - | ||||||||||||||||||
1860 | QObject::disconnect(outgoingData, SIGNAL(readyRead()), q, SLOT(_q_bufferOutgoingData())); | - | ||||||||||||||||||
1861 | QObject::disconnect(outgoingData, SIGNAL(readChannelFinished()), q, SLOT(_q_bufferOutgoingDataFinished())); | - | ||||||||||||||||||
1862 | - | |||||||||||||||||||
1863 | // finally, start the request | - | ||||||||||||||||||
1864 | QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); | - | ||||||||||||||||||
1865 | } executed 58 times by 1 test: end of block Executed by:
| 58 | ||||||||||||||||||
1866 | - | |||||||||||||||||||
1867 | void QNetworkReplyHttpImplPrivate::_q_cacheSaveDeviceAboutToClose() | - | ||||||||||||||||||
1868 | { | - | ||||||||||||||||||
1869 | // do not keep a dangling pointer to the device around (device | - | ||||||||||||||||||
1870 | // is closing because e.g. QAbstractNetworkCache::remove() was called). | - | ||||||||||||||||||
1871 | cacheSaveDevice = 0; | - | ||||||||||||||||||
1872 | } executed 54 times by 3 tests: end of block Executed by:
| 54 | ||||||||||||||||||
1873 | - | |||||||||||||||||||
1874 | void QNetworkReplyHttpImplPrivate::_q_bufferOutgoingData() | - | ||||||||||||||||||
1875 | { | - | ||||||||||||||||||
1876 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
1877 | - | |||||||||||||||||||
1878 | if (!outgoingDataBuffer) {
| 48-58 | ||||||||||||||||||
1879 | // first call, create our buffer | - | ||||||||||||||||||
1880 | outgoingDataBuffer = QSharedPointer<QRingBuffer>::create(); | - | ||||||||||||||||||
1881 | - | |||||||||||||||||||
1882 | QObject::connect(outgoingData, SIGNAL(readyRead()), q, SLOT(_q_bufferOutgoingData())); | - | ||||||||||||||||||
1883 | QObject::connect(outgoingData, SIGNAL(readChannelFinished()), q, SLOT(_q_bufferOutgoingDataFinished())); | - | ||||||||||||||||||
1884 | } executed 58 times by 1 test: end of block Executed by:
| 58 | ||||||||||||||||||
1885 | - | |||||||||||||||||||
1886 | qint64 bytesBuffered = 0; | - | ||||||||||||||||||
1887 | qint64 bytesToBuffer = 0; | - | ||||||||||||||||||
1888 | - | |||||||||||||||||||
1889 | // read data into our buffer | - | ||||||||||||||||||
1890 | forever { | - | ||||||||||||||||||
1891 | bytesToBuffer = outgoingData->bytesAvailable(); | - | ||||||||||||||||||
1892 | // unknown? just try 2 kB, this also ensures we always try to read the EOF | - | ||||||||||||||||||
1893 | if (bytesToBuffer <= 0)
| 48-106 | ||||||||||||||||||
1894 | bytesToBuffer = 2*1024; executed 106 times by 1 test: bytesToBuffer = 2*1024; Executed by:
| 106 | ||||||||||||||||||
1895 | - | |||||||||||||||||||
1896 | char *dst = outgoingDataBuffer->reserve(bytesToBuffer); | - | ||||||||||||||||||
1897 | bytesBuffered = outgoingData->read(dst, bytesToBuffer); | - | ||||||||||||||||||
1898 | - | |||||||||||||||||||
1899 | if (bytesBuffered == -1) {
| 0-154 | ||||||||||||||||||
1900 | // EOF has been reached. | - | ||||||||||||||||||
1901 | outgoingDataBuffer->chop(bytesToBuffer); | - | ||||||||||||||||||
1902 | - | |||||||||||||||||||
1903 | _q_bufferOutgoingDataFinished(); | - | ||||||||||||||||||
1904 | break; never executed: break; | 0 | ||||||||||||||||||
1905 | } else if (bytesBuffered == 0) {
| 48-106 | ||||||||||||||||||
1906 | // nothing read right now, just wait until we get called again | - | ||||||||||||||||||
1907 | outgoingDataBuffer->chop(bytesToBuffer); | - | ||||||||||||||||||
1908 | - | |||||||||||||||||||
1909 | break; executed 106 times by 1 test: break; Executed by:
| 106 | ||||||||||||||||||
1910 | } else { | - | ||||||||||||||||||
1911 | // don't break, try to read() again | - | ||||||||||||||||||
1912 | outgoingDataBuffer->chop(bytesToBuffer - bytesBuffered); | - | ||||||||||||||||||
1913 | } executed 48 times by 1 test: end of block Executed by:
| 48 | ||||||||||||||||||
1914 | } | - | ||||||||||||||||||
1915 | } executed 106 times by 1 test: end of block Executed by:
| 106 | ||||||||||||||||||
1916 | - | |||||||||||||||||||
1917 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
1918 | void QNetworkReplyHttpImplPrivate::_q_networkSessionConnected() | - | ||||||||||||||||||
1919 | { | - | ||||||||||||||||||
1920 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
1921 | - | |||||||||||||||||||
1922 | if (!manager)
| 0-158 | ||||||||||||||||||
1923 | return; never executed: return; | 0 | ||||||||||||||||||
1924 | - | |||||||||||||||||||
1925 | QSharedPointer<QNetworkSession> session = managerPrivate->getNetworkSession(); | - | ||||||||||||||||||
1926 | if (!session)
| 0-158 | ||||||||||||||||||
1927 | return; never executed: return; | 0 | ||||||||||||||||||
1928 | - | |||||||||||||||||||
1929 | if (session->state() != QNetworkSession::Connected)
| 0-158 | ||||||||||||||||||
1930 | return; never executed: return; | 0 | ||||||||||||||||||
1931 | - | |||||||||||||||||||
1932 | switch (state) { | - | ||||||||||||||||||
1933 | case QNetworkReplyPrivate::Buffering: never executed: case QNetworkReplyPrivate::Buffering: | 0 | ||||||||||||||||||
1934 | case QNetworkReplyPrivate::Working: never executed: case QNetworkReplyPrivate::Working: | 0 | ||||||||||||||||||
1935 | case QNetworkReplyPrivate::Reconnecting: never executed: case QNetworkReplyPrivate::Reconnecting: | 0 | ||||||||||||||||||
1936 | // Migrate existing downloads to new network connection. | - | ||||||||||||||||||
1937 | migrateBackend(); | - | ||||||||||||||||||
1938 | break; never executed: break; | 0 | ||||||||||||||||||
1939 | case QNetworkReplyPrivate::WaitingForSession: executed 56 times by 5 tests: case QNetworkReplyPrivate::WaitingForSession: Executed by:
| 56 | ||||||||||||||||||
1940 | // Start waiting requests. | - | ||||||||||||||||||
1941 | QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); | - | ||||||||||||||||||
1942 | break; executed 56 times by 5 tests: break; Executed by:
| 56 | ||||||||||||||||||
1943 | default: executed 102 times by 1 test: default: Executed by:
| 102 | ||||||||||||||||||
1944 | ; | - | ||||||||||||||||||
1945 | } executed 102 times by 1 test: end of block Executed by:
| 102 | ||||||||||||||||||
1946 | } | - | ||||||||||||||||||
1947 | - | |||||||||||||||||||
1948 | void QNetworkReplyHttpImplPrivate::_q_networkSessionStateChanged(QNetworkSession::State sessionState) | - | ||||||||||||||||||
1949 | { | - | ||||||||||||||||||
1950 | if (sessionState == QNetworkSession::Disconnected
| 0 | ||||||||||||||||||
1951 | && state != Idle && state != Reconnecting) {
| 0 | ||||||||||||||||||
1952 | error(QNetworkReplyImpl::NetworkSessionFailedError, | - | ||||||||||||||||||
1953 | QCoreApplication::translate("QNetworkReply", "Network session error.")); | - | ||||||||||||||||||
1954 | finished(); | - | ||||||||||||||||||
1955 | } never executed: end of block | 0 | ||||||||||||||||||
1956 | } never executed: end of block | 0 | ||||||||||||||||||
1957 | - | |||||||||||||||||||
1958 | void QNetworkReplyHttpImplPrivate::_q_networkSessionFailed() | - | ||||||||||||||||||
1959 | { | - | ||||||||||||||||||
1960 | // Abort waiting and working replies. | - | ||||||||||||||||||
1961 | if (state == WaitingForSession || state == Working) {
| 0 | ||||||||||||||||||
1962 | state = Working; | - | ||||||||||||||||||
1963 | QSharedPointer<QNetworkSession> session(manager->d_func()->getNetworkSession()); | - | ||||||||||||||||||
1964 | QString errorStr; | - | ||||||||||||||||||
1965 | if (session)
| 0 | ||||||||||||||||||
1966 | errorStr = session->errorString(); never executed: errorStr = session->errorString(); | 0 | ||||||||||||||||||
1967 | else | - | ||||||||||||||||||
1968 | errorStr = QCoreApplication::translate("QNetworkReply", "Network session error."); never executed: errorStr = QCoreApplication::translate("QNetworkReply", "Network session error."); | 0 | ||||||||||||||||||
1969 | error(QNetworkReplyImpl::NetworkSessionFailedError, errorStr); | - | ||||||||||||||||||
1970 | finished(); | - | ||||||||||||||||||
1971 | } never executed: end of block | 0 | ||||||||||||||||||
1972 | } never executed: end of block | 0 | ||||||||||||||||||
1973 | - | |||||||||||||||||||
1974 | void QNetworkReplyHttpImplPrivate::_q_networkSessionUsagePoliciesChanged(QNetworkSession::UsagePolicies newPolicies) | - | ||||||||||||||||||
1975 | { | - | ||||||||||||||||||
1976 | if (request.attribute(QNetworkRequest::BackgroundRequestAttribute).toBool()) {
| 4-6 | ||||||||||||||||||
1977 | if (newPolicies & QNetworkSession::NoBackgroundTrafficPolicy) {
| 2 | ||||||||||||||||||
1978 | // Abort waiting and working replies. | - | ||||||||||||||||||
1979 | if (state == WaitingForSession || state == Working) {
| 0-2 | ||||||||||||||||||
1980 | state = Working; | - | ||||||||||||||||||
1981 | error(QNetworkReply::BackgroundRequestNotAllowedError, | - | ||||||||||||||||||
1982 | QCoreApplication::translate("QNetworkReply", "Background request not allowed.")); | - | ||||||||||||||||||
1983 | finished(); | - | ||||||||||||||||||
1984 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
1985 | // ### if canResume(), then we could resume automatically | - | ||||||||||||||||||
1986 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
1987 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
1988 | - | |||||||||||||||||||
1989 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||
1990 | #endif | - | ||||||||||||||||||
1991 | - | |||||||||||||||||||
1992 | - | |||||||||||||||||||
1993 | // need to have this function since the reply is a private member variable | - | ||||||||||||||||||
1994 | // and the special backends need to access this. | - | ||||||||||||||||||
1995 | void QNetworkReplyHttpImplPrivate::emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal) | - | ||||||||||||||||||
1996 | { | - | ||||||||||||||||||
1997 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
1998 | if (isFinished)
| 0-2695 | ||||||||||||||||||
1999 | return; never executed: return; | 0 | ||||||||||||||||||
2000 | - | |||||||||||||||||||
2001 | if (!emitAllUploadProgressSignals) {
| 64-2631 | ||||||||||||||||||
2002 | //choke signal emissions, except the first and last signals which are unconditional | - | ||||||||||||||||||
2003 | if (uploadProgressSignalChoke.isValid()) {
| 133-2498 | ||||||||||||||||||
2004 | if (bytesSent != bytesTotal && uploadProgressSignalChoke.elapsed() < progressSignalInterval) {
| 21-2425 | ||||||||||||||||||
2005 | return; executed 2404 times by 2 tests: return; Executed by:
| 2404 | ||||||||||||||||||
2006 | } | - | ||||||||||||||||||
2007 | uploadProgressSignalChoke.restart(); | - | ||||||||||||||||||
2008 | } else { executed 94 times by 2 tests: end of block Executed by:
| 94 | ||||||||||||||||||
2009 | uploadProgressSignalChoke.start(); | - | ||||||||||||||||||
2010 | } executed 133 times by 2 tests: end of block Executed by:
| 133 | ||||||||||||||||||
2011 | } | - | ||||||||||||||||||
2012 | - | |||||||||||||||||||
2013 | emit q->uploadProgress(bytesSent, bytesTotal); | - | ||||||||||||||||||
2014 | } executed 291 times by 2 tests: end of block Executed by:
| 291 | ||||||||||||||||||
2015 | - | |||||||||||||||||||
2016 | QNonContiguousByteDevice* QNetworkReplyHttpImplPrivate::createUploadByteDevice() | - | ||||||||||||||||||
2017 | { | - | ||||||||||||||||||
2018 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
2019 | - | |||||||||||||||||||
2020 | if (outgoingDataBuffer)
| 99-101 | ||||||||||||||||||
2021 | uploadByteDevice = QNonContiguousByteDeviceFactory::createShared(outgoingDataBuffer); executed 99 times by 1 test: uploadByteDevice = QNonContiguousByteDeviceFactory::createShared(outgoingDataBuffer); Executed by:
| 99 | ||||||||||||||||||
2022 | else if (outgoingData) {
| 4-97 | ||||||||||||||||||
2023 | uploadByteDevice = QNonContiguousByteDeviceFactory::createShared(outgoingData); | - | ||||||||||||||||||
2024 | } else { executed 97 times by 3 tests: end of block Executed by:
| 97 | ||||||||||||||||||
2025 | return 0; executed 4 times by 1 test: return 0; Executed by:
| 4 | ||||||||||||||||||
2026 | } | - | ||||||||||||||||||
2027 | - | |||||||||||||||||||
2028 | // We want signal emissions only for normal asynchronous uploads | - | ||||||||||||||||||
2029 | if (!synchronous)
| 41-155 | ||||||||||||||||||
2030 | QObject::connect(uploadByteDevice.data(), SIGNAL(readProgress(qint64,qint64)), executed 155 times by 3 tests: QObject::connect(uploadByteDevice.data(), qFlagLocation("2""readProgress(qint64,qint64)" "\0" __FILE__ ":" "2030"), q, qFlagLocation("1""emitReplyUploadProgress(qint64,qint64)" "\0" __FILE__ ":" "2031")); Executed by:
| 155 | ||||||||||||||||||
2031 | q, SLOT(emitReplyUploadProgress(qint64,qint64))); executed 155 times by 3 tests: QObject::connect(uploadByteDevice.data(), qFlagLocation("2""readProgress(qint64,qint64)" "\0" __FILE__ ":" "2030"), q, qFlagLocation("1""emitReplyUploadProgress(qint64,qint64)" "\0" __FILE__ ":" "2031")); Executed by:
| 155 | ||||||||||||||||||
2032 | - | |||||||||||||||||||
2033 | return uploadByteDevice.data(); executed 196 times by 3 tests: return uploadByteDevice.data(); Executed by:
| 196 | ||||||||||||||||||
2034 | } | - | ||||||||||||||||||
2035 | - | |||||||||||||||||||
2036 | void QNetworkReplyHttpImplPrivate::_q_finished() | - | ||||||||||||||||||
2037 | { | - | ||||||||||||||||||
2038 | // This gets called queued, just forward to real call then | - | ||||||||||||||||||
2039 | finished(); | - | ||||||||||||||||||
2040 | } executed 32 times by 2 tests: end of block Executed by:
| 32 | ||||||||||||||||||
2041 | - | |||||||||||||||||||
2042 | void QNetworkReplyHttpImplPrivate::finished() | - | ||||||||||||||||||
2043 | { | - | ||||||||||||||||||
2044 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
2045 | - | |||||||||||||||||||
2046 | if (state == Finished || state == Aborted || state == WaitingForSession)
| 0-869 | ||||||||||||||||||
2047 | return; never executed: return; | 0 | ||||||||||||||||||
2048 | - | |||||||||||||||||||
2049 | QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); | - | ||||||||||||||||||
2050 | if (preMigrationDownloaded != Q_INT64_C(-1))
| 0-869 | ||||||||||||||||||
2051 | totalSize = totalSize.toLongLong() + preMigrationDownloaded; never executed: totalSize = totalSize.toLongLong() + preMigrationDownloaded; | 0 | ||||||||||||||||||
2052 | - | |||||||||||||||||||
2053 | if (manager) {
| 0-869 | ||||||||||||||||||
2054 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
2055 | QSharedPointer<QNetworkSession> session = managerPrivate->getNetworkSession(); | - | ||||||||||||||||||
2056 | if (session && session->state() == QNetworkSession::Roaming &&
| 0-869 | ||||||||||||||||||
2057 | state == Working && errorCode != QNetworkReply::OperationCanceledError) {
| 0 | ||||||||||||||||||
2058 | // only content with a known size will fail with a temporary network failure error | - | ||||||||||||||||||
2059 | if (!totalSize.isNull()) {
| 0 | ||||||||||||||||||
2060 | if (bytesDownloaded != totalSize) {
| 0 | ||||||||||||||||||
2061 | if (migrateBackend()) {
| 0 | ||||||||||||||||||
2062 | // either we are migrating or the request is finished/aborted | - | ||||||||||||||||||
2063 | if (state == Reconnecting || state == WaitingForSession) {
| 0 | ||||||||||||||||||
2064 | return; // exit early if we are migrating. never executed: return; | 0 | ||||||||||||||||||
2065 | } | - | ||||||||||||||||||
2066 | } else { never executed: end of block | 0 | ||||||||||||||||||
2067 | error(QNetworkReply::TemporaryNetworkFailureError, | - | ||||||||||||||||||
2068 | QNetworkReply::tr("Temporary network failure.")); | - | ||||||||||||||||||
2069 | } never executed: end of block | 0 | ||||||||||||||||||
2070 | } | - | ||||||||||||||||||
2071 | } never executed: end of block | 0 | ||||||||||||||||||
2072 | } never executed: end of block | 0 | ||||||||||||||||||
2073 | #endif | - | ||||||||||||||||||
2074 | } executed 869 times by 7 tests: end of block Executed by:
| 869 | ||||||||||||||||||
2075 | - | |||||||||||||||||||
2076 | // if we don't know the total size of or we received everything save the cache | - | ||||||||||||||||||
2077 | if (totalSize.isNull() || totalSize == -1 || bytesDownloaded == totalSize)
| 0-550 | ||||||||||||||||||
2078 | completeCacheSave(); executed 837 times by 7 tests: completeCacheSave(); Executed by:
| 837 | ||||||||||||||||||
2079 | - | |||||||||||||||||||
2080 | // We check for errorCode too as in case of SSL handshake failure, we still | - | ||||||||||||||||||
2081 | // get the HTTP redirect status code (301, 303 etc) | - | ||||||||||||||||||
2082 | if (isHttpRedirectResponse() && errorCode == QNetworkReply::NoError)
| 1-863 | ||||||||||||||||||
2083 | return; executed 5 times by 1 test: return; Executed by:
| 5 | ||||||||||||||||||
2084 | - | |||||||||||||||||||
2085 | state = Finished; | - | ||||||||||||||||||
2086 | q->setFinished(true); | - | ||||||||||||||||||
2087 | - | |||||||||||||||||||
2088 | if (totalSize.isNull() || totalSize == -1) {
| 0-550 | ||||||||||||||||||
2089 | emit q->downloadProgress(bytesDownloaded, bytesDownloaded); | - | ||||||||||||||||||
2090 | } else { executed 314 times by 5 tests: end of block Executed by:
| 314 | ||||||||||||||||||
2091 | emit q->downloadProgress(bytesDownloaded, totalSize.toLongLong()); | - | ||||||||||||||||||
2092 | } executed 550 times by 6 tests: end of block Executed by:
| 550 | ||||||||||||||||||
2093 | - | |||||||||||||||||||
2094 | if (bytesUploaded == -1 && (outgoingData || outgoingDataBuffer))
| 0-864 | ||||||||||||||||||
2095 | emit q->uploadProgress(0, 0); executed 195 times by 2 tests: q->uploadProgress(0, 0); Executed by:
| 195 | ||||||||||||||||||
2096 | - | |||||||||||||||||||
2097 | emit q->readChannelFinished(); | - | ||||||||||||||||||
2098 | emit q->finished(); | - | ||||||||||||||||||
2099 | } executed 864 times by 7 tests: end of block Executed by:
| 864 | ||||||||||||||||||
2100 | - | |||||||||||||||||||
2101 | void QNetworkReplyHttpImplPrivate::_q_error(QNetworkReplyImpl::NetworkError code, const QString &errorMessage) | - | ||||||||||||||||||
2102 | { | - | ||||||||||||||||||
2103 | this->error(code, errorMessage); | - | ||||||||||||||||||
2104 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||
2105 | - | |||||||||||||||||||
2106 | - | |||||||||||||||||||
2107 | void QNetworkReplyHttpImplPrivate::error(QNetworkReplyImpl::NetworkError code, const QString &errorMessage) | - | ||||||||||||||||||
2108 | { | - | ||||||||||||||||||
2109 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
2110 | // Can't set and emit multiple errors. | - | ||||||||||||||||||
2111 | if (errorCode != QNetworkReply::NoError) {
| 0-122 | ||||||||||||||||||
2112 | qWarning("QNetworkReplyImplPrivate::error: Internal problem, this method must only be called once."); | - | ||||||||||||||||||
2113 | return; never executed: return; | 0 | ||||||||||||||||||
2114 | } | - | ||||||||||||||||||
2115 | - | |||||||||||||||||||
2116 | errorCode = code; | - | ||||||||||||||||||
2117 | q->setErrorString(errorMessage); | - | ||||||||||||||||||
2118 | - | |||||||||||||||||||
2119 | // note: might not be a good idea, since users could decide to delete us | - | ||||||||||||||||||
2120 | // which would delete the backend too... | - | ||||||||||||||||||
2121 | // maybe we should protect the backend | - | ||||||||||||||||||
2122 | emit q->error(code); | - | ||||||||||||||||||
2123 | } executed 122 times by 4 tests: end of block Executed by:
| 122 | ||||||||||||||||||
2124 | - | |||||||||||||||||||
2125 | void QNetworkReplyHttpImplPrivate::_q_metaDataChanged() | - | ||||||||||||||||||
2126 | { | - | ||||||||||||||||||
2127 | // FIXME merge this with replyDownloadMetaData(); ? | - | ||||||||||||||||||
2128 | - | |||||||||||||||||||
2129 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
2130 | // 1. do we have cookies? | - | ||||||||||||||||||
2131 | // 2. are we allowed to set them? | - | ||||||||||||||||||
2132 | if (cookedHeaders.contains(QNetworkRequest::SetCookieHeader) && manager
| 0-801 | ||||||||||||||||||
2133 | && (static_cast<QNetworkRequest::LoadControl>
| 0-13 | ||||||||||||||||||
2134 | (request.attribute(QNetworkRequest::CookieSaveControlAttribute,
| 0-13 | ||||||||||||||||||
2135 | QNetworkRequest::Automatic).toInt()) == QNetworkRequest::Automatic)) {
| 0-13 | ||||||||||||||||||
2136 | QList<QNetworkCookie> cookies = | - | ||||||||||||||||||
2137 | qvariant_cast<QList<QNetworkCookie> >(cookedHeaders.value(QNetworkRequest::SetCookieHeader)); | - | ||||||||||||||||||
2138 | QNetworkCookieJar *jar = manager->cookieJar(); | - | ||||||||||||||||||
2139 | if (jar)
| 0-13 | ||||||||||||||||||
2140 | jar->setCookiesFromUrl(cookies, url); executed 13 times by 1 test: jar->setCookiesFromUrl(cookies, url); Executed by:
| 13 | ||||||||||||||||||
2141 | } executed 13 times by 1 test: end of block Executed by:
| 13 | ||||||||||||||||||
2142 | emit q->metaDataChanged(); | - | ||||||||||||||||||
2143 | } executed 814 times by 6 tests: end of block Executed by:
| 814 | ||||||||||||||||||
2144 | - | |||||||||||||||||||
2145 | /* | - | ||||||||||||||||||
2146 | Migrates the backend of the QNetworkReply to a new network connection if required. Returns | - | ||||||||||||||||||
2147 | true if the reply is migrated or it is not required; otherwise returns \c false. | - | ||||||||||||||||||
2148 | */ | - | ||||||||||||||||||
2149 | bool QNetworkReplyHttpImplPrivate::migrateBackend() | - | ||||||||||||||||||
2150 | { | - | ||||||||||||||||||
2151 | Q_Q(QNetworkReplyHttpImpl); | - | ||||||||||||||||||
2152 | - | |||||||||||||||||||
2153 | // Network reply is already finished or aborted, don't need to migrate. | - | ||||||||||||||||||
2154 | if (state == Finished || state == Aborted)
| 0 | ||||||||||||||||||
2155 | return true; never executed: return true; | 0 | ||||||||||||||||||
2156 | - | |||||||||||||||||||
2157 | // Backend does not support resuming download. | - | ||||||||||||||||||
2158 | if (!canResume())
| 0 | ||||||||||||||||||
2159 | return false; never executed: return false; | 0 | ||||||||||||||||||
2160 | - | |||||||||||||||||||
2161 | // Request has outgoing data, not migrating. | - | ||||||||||||||||||
2162 | if (outgoingData)
| 0 | ||||||||||||||||||
2163 | return false; never executed: return false; | 0 | ||||||||||||||||||
2164 | - | |||||||||||||||||||
2165 | // Request is serviced from the cache, don't need to migrate. | - | ||||||||||||||||||
2166 | if (cacheLoadDevice)
| 0 | ||||||||||||||||||
2167 | return true; never executed: return true; | 0 | ||||||||||||||||||
2168 | - | |||||||||||||||||||
2169 | state = Reconnecting; | - | ||||||||||||||||||
2170 | - | |||||||||||||||||||
2171 | cookedHeaders.clear(); | - | ||||||||||||||||||
2172 | rawHeaders.clear(); | - | ||||||||||||||||||
2173 | - | |||||||||||||||||||
2174 | preMigrationDownloaded = bytesDownloaded; | - | ||||||||||||||||||
2175 | - | |||||||||||||||||||
2176 | setResumeOffset(bytesDownloaded); | - | ||||||||||||||||||
2177 | - | |||||||||||||||||||
2178 | emit q->abortHttpRequest(); | - | ||||||||||||||||||
2179 | - | |||||||||||||||||||
2180 | QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); | - | ||||||||||||||||||
2181 | - | |||||||||||||||||||
2182 | return true; never executed: return true; | 0 | ||||||||||||||||||
2183 | } | - | ||||||||||||||||||
2184 | - | |||||||||||||||||||
2185 | - | |||||||||||||||||||
2186 | void QNetworkReplyHttpImplPrivate::createCache() | - | ||||||||||||||||||
2187 | { | - | ||||||||||||||||||
2188 | // check if we can save and if we're allowed to | - | ||||||||||||||||||
2189 | if (!managerPrivate->networkCache
| 75-712 | ||||||||||||||||||
2190 | || !request.attribute(QNetworkRequest::CacheSaveControlAttribute, true).toBool())
| 10-65 | ||||||||||||||||||
2191 | return; executed 722 times by 5 tests: return; Executed by:
| 722 | ||||||||||||||||||
2192 | cacheEnabled = true; | - | ||||||||||||||||||
2193 | } executed 65 times by 3 tests: end of block Executed by:
| 65 | ||||||||||||||||||
2194 | - | |||||||||||||||||||
2195 | bool QNetworkReplyHttpImplPrivate::isCachingEnabled() const | - | ||||||||||||||||||
2196 | { | - | ||||||||||||||||||
2197 | return (cacheEnabled && managerPrivate->networkCache != 0); executed 787 times by 6 tests: return (cacheEnabled && managerPrivate->networkCache != 0); Executed by:
| 0-787 | ||||||||||||||||||
2198 | } | - | ||||||||||||||||||
2199 | - | |||||||||||||||||||
2200 | void QNetworkReplyHttpImplPrivate::setCachingEnabled(bool enable) | - | ||||||||||||||||||
2201 | { | - | ||||||||||||||||||
2202 | if (!enable && !cacheEnabled)
| 0-787 | ||||||||||||||||||
2203 | return; // nothing to do executed 27 times by 2 tests: return; Executed by:
| 27 | ||||||||||||||||||
2204 | if (enable && cacheEnabled)
| 0-787 | ||||||||||||||||||
2205 | return; // nothing to do either! never executed: return; | 0 | ||||||||||||||||||
2206 | - | |||||||||||||||||||
2207 | if (enable) {
| 0-787 | ||||||||||||||||||
2208 | if (bytesDownloaded) {
| 0-787 | ||||||||||||||||||
2209 | qDebug() << "setCachingEnabled: " << bytesDownloaded << " bytesDownloaded"; | - | ||||||||||||||||||
2210 | // refuse to enable in this case | - | ||||||||||||||||||
2211 | qCritical("QNetworkReplyImpl: backend error: caching was enabled after some bytes had been written"); | - | ||||||||||||||||||
2212 | return; never executed: return; | 0 | ||||||||||||||||||
2213 | } | - | ||||||||||||||||||
2214 | - | |||||||||||||||||||
2215 | createCache(); | - | ||||||||||||||||||
2216 | } else { executed 787 times by 6 tests: end of block Executed by:
| 787 | ||||||||||||||||||
2217 | // someone told us to turn on, then back off? | - | ||||||||||||||||||
2218 | // ok... but you should make up your mind | - | ||||||||||||||||||
2219 | qDebug("QNetworkReplyImpl: setCachingEnabled(true) called after setCachingEnabled(false)"); | - | ||||||||||||||||||
2220 | managerPrivate->networkCache->remove(url); | - | ||||||||||||||||||
2221 | cacheSaveDevice = 0; | - | ||||||||||||||||||
2222 | cacheEnabled = false; | - | ||||||||||||||||||
2223 | } never executed: end of block | 0 | ||||||||||||||||||
2224 | } | - | ||||||||||||||||||
2225 | - | |||||||||||||||||||
2226 | bool QNetworkReplyHttpImplPrivate::isCachingAllowed() const | - | ||||||||||||||||||
2227 | { | - | ||||||||||||||||||
2228 | return operation == QNetworkAccessManager::GetOperation || operation == QNetworkAccessManager::HeadOperation; executed 64 times by 3 tests: return operation == QNetworkAccessManager::GetOperation || operation == QNetworkAccessManager::HeadOperation; Executed by:
| 0-64 | ||||||||||||||||||
2229 | } | - | ||||||||||||||||||
2230 | - | |||||||||||||||||||
2231 | void QNetworkReplyHttpImplPrivate::completeCacheSave() | - | ||||||||||||||||||
2232 | { | - | ||||||||||||||||||
2233 | if (cacheEnabled && errorCode != QNetworkReplyImpl::NoError) {
| 0-781 | ||||||||||||||||||
2234 | managerPrivate->networkCache->remove(url); | - | ||||||||||||||||||
2235 | } else if (cacheEnabled && cacheSaveDevice) { never executed: end of block
| 0-781 | ||||||||||||||||||
2236 | managerPrivate->networkCache->insert(cacheSaveDevice); | - | ||||||||||||||||||
2237 | } executed 53 times by 2 tests: end of block Executed by:
| 53 | ||||||||||||||||||
2238 | cacheSaveDevice = 0; | - | ||||||||||||||||||
2239 | cacheEnabled = false; | - | ||||||||||||||||||
2240 | } executed 837 times by 7 tests: end of block Executed by:
| 837 | ||||||||||||||||||
2241 | - | |||||||||||||||||||
2242 | QT_END_NAMESPACE | - | ||||||||||||||||||
2243 | - | |||||||||||||||||||
2244 | #endif // QT_NO_HTTP | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |