access/qnetworkreplyhttpimpl.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9 -
10 -
11 -
12class QNetworkProxy; -
13 -
14static inline bool isSeparator(register char c) -
15{ -
16 static const char separators[] = "()<>@,;:\\\"/[]?={}"; -
17 return isLWS(c) || strchr(separators, c) != 0;
-
18} -
19 -
20 -
21static QHash<QByteArray, QByteArray> parseHttpOptionHeader(const QByteArray &header) -
22{ -
23 -
24 -
25 -
26 -
27 QHash<QByteArray, QByteArray> result; -
28 -
29 int pos = 0; -
30 while (true) {
-
31 -
32 pos = nextNonWhitespace(header, pos); -
33 if (pos == header.length())
-
34 return result;
-
35 -
36 -
37 int comma = header.indexOf(',', pos); -
38 int equal = header.indexOf('=', pos); -
39 if (comma == pos || equal == pos)
-
40 -
41 return result;
-
42 -
43 -
44 -
45 int end = comma; -
46 if (end == -1)
-
47 end = header.length();
-
48 if (equal != -1 && end > equal)
-
49 end = equal;
-
50 QByteArray key = QByteArray(header.constData() + pos, end - pos).trimmed().toLower(); -
51 pos = end + 1; -
52 -
53 if (uint(equal) < uint(comma)) {
-
54 -
55 -
56 pos = nextNonWhitespace(header, pos); -
57 if (pos == header.length())
-
58 -
59 return result;
-
60 -
61 QByteArray value; -
62 value.reserve(header.length() - pos); -
63 if (header.at(pos) == '"') {
-
64 -
65 -
66 -
67 -
68 ++pos; -
69 while (pos < header.length()) {
-
70 register char c = header.at(pos); -
71 if (c == '"') {
-
72 -
73 break;
-
74 } else if (c == '\\') {
-
75 ++pos; -
76 if (pos >= header.length())
-
77 -
78 return result;
-
79 c = header.at(pos); -
80 }
-
81 -
82 value += c; -
83 ++pos; -
84 }
-
85 } else {
-
86 -
87 while (pos < header.length()) {
-
88 register char c = header.at(pos); -
89 if (isSeparator(c))
-
90 break;
-
91 value += c; -
92 ++pos; -
93 }
-
94 }
-
95 -
96 result.insert(key, value); -
97 -
98 -
99 comma = header.indexOf(',', pos); -
100 if (comma == -1)
-
101 return result;
-
102 pos = comma + 1; -
103 } else {
-
104 -
105 -
106 result.insert(key, QByteArray()); -
107 }
-
108 } -
109}
-
110 -
111QNetworkReplyHttpImpl::QNetworkReplyHttpImpl(QNetworkAccessManager* const manager, -
112 const QNetworkRequest& request, -
113 QNetworkAccessManager::Operation& operation, -
114 QIODevice* outgoingData) -
115 : QNetworkReply(*new QNetworkReplyHttpImplPrivate, manager) -
116{ -
117 QNetworkReplyHttpImplPrivate * const d = d_func(); -
118 d->manager = manager; -
119 d->managerPrivate = manager->d_func(); -
120 d->request = request; -
121 d->operation = operation; -
122 d->outgoingData = outgoingData; -
123 d->url = request.url(); -
124 -
125 d->sslConfiguration = request.sslConfiguration(); -
126 -
127 -
128 -
129 QIODevice::open(QIODevice::ReadOnly); -
130 -
131 -
132 -
133 -
134 QVariant synchronousHttpAttribute = request.attribute( -
135 static_cast<QNetworkRequest::Attribute>(QNetworkRequest::SynchronousRequestAttribute)); -
136 if (synchronousHttpAttribute.isValid()) {
-
137 d->synchronous = synchronousHttpAttribute.toBool(); -
138 if (d->synchronous && outgoingData) {
-
139 -
140 -
141 d->outgoingDataBuffer = QSharedPointer<QRingBuffer>(new QRingBuffer()); -
142 qint64 previousDataSize = 0; -
143 do { -
144 previousDataSize = d->outgoingDataBuffer->size(); -
145 d->outgoingDataBuffer->append(d->outgoingData->readAll()); -
146 } while (d->outgoingDataBuffer->size() != previousDataSize);
-
147 d->_q_startOperation(); -
148 return;
-
149 } -
150 }
-
151 -
152 -
153 if (outgoingData) {
-
154 -
155 -
156 if (!d->outgoingData->isSequential()) {
-
157 -
158 -
159 QMetaObject::invokeMethod(this, "_q_startOperation", Qt::QueuedConnection); -
160 -
161 } else {
-
162 bool bufferingDisallowed = -
163 request.attribute(QNetworkRequest::DoNotBufferUploadDataAttribute, -
164 false).toBool(); -
165 -
166 if (bufferingDisallowed) {
-
167 -
168 -
169 if (request.header(QNetworkRequest::ContentLengthHeader).isValid()) {
-
170 QMetaObject::invokeMethod(this, "_q_startOperation", Qt::QueuedConnection); -
171 -
172 } else {
-
173 d->state = d->Buffering; -
174 QMetaObject::invokeMethod(this, "_q_bufferOutgoingData", Qt::QueuedConnection); -
175 }
-
176 } else { -
177 -
178 d->state = d->Buffering; -
179 QMetaObject::invokeMethod(this, "_q_bufferOutgoingData", Qt::QueuedConnection); -
180 }
-
181 } -
182 } else { -
183 -
184 d->_q_startOperation(); -
185 }
-
186} -
187 -
188QNetworkReplyHttpImpl::~QNetworkReplyHttpImpl() -
189{ -
190 -
191} -
192 -
193void QNetworkReplyHttpImpl::close() -
194{ -
195 QNetworkReplyHttpImplPrivate * const d = d_func(); -
196 -
197 if (d->state == QNetworkReplyHttpImplPrivate::Aborted ||
-
198 d->state == QNetworkReplyHttpImplPrivate::Finished)
-
199 return;
-
200 -
201 -
202 -
203 QNetworkReply::close(); -
204 -
205 -
206 -
207 d->error(OperationCanceledError, tr("Operation canceled")); -
208 d->finished(); -
209}
-
210 -
211void QNetworkReplyHttpImpl::abort() -
212{ -
213 QNetworkReplyHttpImplPrivate * const d = d_func(); -
214 -
215 if (d->state == QNetworkReplyHttpImplPrivate::Finished || d->state == QNetworkReplyHttpImplPrivate::Aborted)
-
216 return;
-
217 -
218 QNetworkReply::close(); -
219 -
220 if (d->state != QNetworkReplyHttpImplPrivate::Finished) {
-
221 -
222 -
223 d->error(OperationCanceledError, tr("Operation canceled")); -
224 d->finished(); -
225 }
-
226 -
227 d->state = QNetworkReplyHttpImplPrivate::Aborted; -
228 -
229 abortHttpRequest(); -
230}
-
231 -
232qint64 QNetworkReplyHttpImpl::bytesAvailable() const -
233{ -
234 const QNetworkReplyHttpImplPrivate * const d = d_func(); -
235 -
236 -
237 if (d->cacheLoadDevice) {
-
238 return QNetworkReply::bytesAvailable() + d->cacheLoadDevice->bytesAvailable() + d->downloadMultiBuffer.byteAmount();
-
239 } -
240 -
241 -
242 if (d->downloadZerocopyBuffer) {
-
243 return QNetworkReply::bytesAvailable() + d->downloadBufferCurrentSize - d->downloadBufferReadPosition;
-
244 } -
245 -
246 -
247 return QNetworkReply::bytesAvailable() + d->downloadMultiBuffer.byteAmount();
-
248} -
249 -
250bool QNetworkReplyHttpImpl::isSequential () const -
251{ -
252 -
253 -
254 return true;
-
255} -
256 -
257qint64 QNetworkReplyHttpImpl::size() const -
258{ -
259 -
260 return QNetworkReply::size();
-
261} -
262 -
263qint64 QNetworkReplyHttpImpl::readData(char* data, qint64 maxlen) -
264{ -
265 QNetworkReplyHttpImplPrivate * const d = d_func(); -
266 -
267 -
268 if (d->cacheLoadDevice) {
-
269 -
270 -
271 -
272 -
273 if (!d->downloadMultiBuffer.isEmpty()) {
-
274 return d->downloadMultiBuffer.read(data, maxlen);
-
275 } -
276 -
277 qint64 ret = d->cacheLoadDevice->read(data, maxlen); -
278 return ret;
-
279 } -
280 -
281 -
282 if (d->downloadZerocopyBuffer) {
-
283 -
284 -
285 qint64 howMuch = qMin(maxlen, (d->downloadBufferCurrentSize - d->downloadBufferReadPosition)); -
286 memcpy(data, d->downloadZerocopyBuffer + d->downloadBufferReadPosition, howMuch); -
287 d->downloadBufferReadPosition += howMuch; -
288 return howMuch;
-
289 -
290 } -
291 -
292 -
293 if (d->downloadMultiBuffer.isEmpty()) {
-
294 if (d->state == d->Finished || d->state == d->Aborted)
-
295 return -1;
-
296 return 0;
-
297 } -
298 -
299 if (maxlen == 1) {
-
300 -
301 *data = d->downloadMultiBuffer.getChar(); -
302 if (readBufferSize())
-
303 readBufferFreed(1);
-
304 return 1;
-
305 } -
306 -
307 maxlen = qMin<qint64>(maxlen, d->downloadMultiBuffer.byteAmount()); -
308 qint64 bytesRead = d->downloadMultiBuffer.read(data, maxlen); -
309 if (readBufferSize())
-
310 readBufferFreed(bytesRead);
-
311 return bytesRead;
-
312} -
313 -
314void QNetworkReplyHttpImpl::setReadBufferSize(qint64 size) -
315{ -
316 QNetworkReply::setReadBufferSize(size); -
317 readBufferSizeChanged(size); -
318 return;
-
319} -
320 -
321bool QNetworkReplyHttpImpl::canReadLine () const -
322{ -
323 const QNetworkReplyHttpImplPrivate * const d = d_func(); -
324 -
325 if (QNetworkReply::canReadLine())
-
326 return true;
-
327 -
328 if (d->cacheLoadDevice)
-
329 return d->cacheLoadDevice->canReadLine() || d->downloadMultiBuffer.canReadLine();
-
330 -
331 if (d->downloadZerocopyBuffer)
-
332 return memchr(d->downloadZerocopyBuffer + d->downloadBufferReadPosition, '\n', d->downloadBufferCurrentSize - d->downloadBufferReadPosition);
-
333 -
334 return d->downloadMultiBuffer.canReadLine();
-
335} -
336 -
337 -
338void QNetworkReplyHttpImpl::ignoreSslErrors() -
339{ -
340 QNetworkReplyHttpImplPrivate * const d = d_func(); -
341 -
342 d->pendingIgnoreAllSslErrors = true; -
343}
-
344 -
345void QNetworkReplyHttpImpl::ignoreSslErrorsImplementation(const QList<QSslError> &errors) -
346{ -
347 QNetworkReplyHttpImplPrivate * const d = d_func(); -
348 -
349 -
350 -
351 d->pendingIgnoreSslErrorsList = errors; -
352}
-
353 -
354void QNetworkReplyHttpImpl::setSslConfigurationImplementation(const QSslConfiguration &newconfig) -
355{ -
356 -
357 -
358 (void)newconfig;; -
359}
-
360 -
361void QNetworkReplyHttpImpl::sslConfigurationImplementation(QSslConfiguration &configuration) const -
362{ -
363 const QNetworkReplyHttpImplPrivate * const d = d_func(); -
364 configuration = d->sslConfiguration; -
365}
-
366 -
367 -
368QNetworkReplyHttpImplPrivate::QNetworkReplyHttpImplPrivate() -
369 : QNetworkReplyPrivate() -
370 , manager(0) -
371 , managerPrivate(0) -
372 , synchronous(false) -
373 , state(Idle) -
374 , statusCode(0) -
375 , outgoingData(0) -
376 , bytesUploaded(-1) -
377 , cacheLoadDevice(0) -
378 , loadingFromCache(false) -
379 , cacheSaveDevice(0) -
380 , cacheEnabled(false) -
381 , resumeOffset(0) -
382 , preMigrationDownloaded(-1) -
383 , bytesDownloaded(0) -
384 , downloadBufferReadPosition(0) -
385 , downloadBufferCurrentSize(0) -
386 , downloadZerocopyBuffer(0) -
387 , pendingDownloadDataEmissions(new QAtomicInt()) -
388 , pendingDownloadProgressEmissions(new QAtomicInt()) -
389 -
390 , pendingIgnoreAllSslErrors(false) -
391 -
392 -
393{ -
394}
-
395 -
396QNetworkReplyHttpImplPrivate::~QNetworkReplyHttpImplPrivate() -
397{ -
398 QNetworkReplyHttpImpl * const q = q_func(); -
399 -
400 q->abortHttpRequest(); -
401}
-
402 -
403 -
404 -
405 -
406 -
407 -
408 -
409bool QNetworkReplyHttpImplPrivate::loadFromCacheIfAllowed(QHttpNetworkRequest &httpRequest) -
410{ -
411 QNetworkRequest::CacheLoadControl CacheLoadControlAttribute = -
412 (QNetworkRequest::CacheLoadControl)request.attribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork).toInt(); -
413 if (CacheLoadControlAttribute == QNetworkRequest::AlwaysNetwork) {
-
414 -
415 -
416 if (!request.rawHeaderList().contains("Cache-Control")) {
-
417 httpRequest.setHeaderField("Cache-Control", "no-cache"); -
418 httpRequest.setHeaderField("Pragma", "no-cache"); -
419 }
-
420 return false;
-
421 } -
422 -
423 -
424 -
425 if (request.hasRawHeader("Range"))
-
426 return false;
-
427 -
428 QAbstractNetworkCache *nc = managerPrivate->networkCache; -
429 if (!nc)
-
430 return false;
-
431 -
432 QNetworkCacheMetaData metaData = nc->metaData(request.url()); -
433 if (!metaData.isValid())
-
434 return false;
-
435 -
436 if (!metaData.saveToDisk())
-
437 return false;
-
438 -
439 QNetworkHeadersPrivate cacheHeaders; -
440 QNetworkHeadersPrivate::RawHeadersList::ConstIterator it; -
441 cacheHeaders.setAllRawHeaders(metaData.rawHeaders()); -
442 -
443 it = cacheHeaders.findRawHeader("etag"); -
444 if (it != cacheHeaders.rawHeaders.constEnd())
-
445 httpRequest.setHeaderField("If-None-Match", it->second);
-
446 -
447 QDateTime lastModified = metaData.lastModified(); -
448 if (lastModified.isValid())
-
449 httpRequest.setHeaderField("If-Modified-Since", QNetworkHeadersPrivate::toHttpDate(lastModified));
-
450 -
451 it = cacheHeaders.findRawHeader("Cache-Control"); -
452 if (it != cacheHeaders.rawHeaders.constEnd()) {
-
453 QHash<QByteArray, QByteArray> cacheControl = parseHttpOptionHeader(it->second); -
454 if (cacheControl.contains("must-revalidate"))
-
455 return false;
-
456 }
-
457 -
458 QDateTime currentDateTime = QDateTime::currentDateTime(); -
459 QDateTime expirationDate = metaData.expirationDate(); -
460 -
461 bool response_is_fresh; -
462 if (!expirationDate.isValid()) {
-
463 int age_value = 0; -
464 it = cacheHeaders.findRawHeader("age"); -
465 if (it != cacheHeaders.rawHeaders.constEnd())
-
466 age_value = it->second.toInt();
-
467 -
468 QDateTime dateHeader; -
469 int date_value = 0; -
470 it = cacheHeaders.findRawHeader("date"); -
471 if (it != cacheHeaders.rawHeaders.constEnd()) {
-
472 dateHeader = QNetworkHeadersPrivate::fromHttpDate(it->second); -
473 date_value = dateHeader.toTime_t(); -
474 }
-
475 -
476 int now = currentDateTime.toUTC().toTime_t(); -
477 int request_time = now; -
478 int response_time = now; -
479 -
480 -
481 int apparent_age = qMax(0, response_time - date_value); -
482 int corrected_received_age = qMax(apparent_age, age_value); -
483 int response_delay = response_time - request_time; -
484 int corrected_initial_age = corrected_received_age + response_delay; -
485 int resident_time = now - response_time; -
486 int current_age = corrected_initial_age + resident_time; -
487 -
488 -
489 if (!expirationDate.isValid()) {
-
490 if (lastModified.isValid()) {
-
491 int diff = currentDateTime.secsTo(lastModified); -
492 expirationDate = lastModified; -
493 expirationDate.addSecs(diff / 10); -
494 if (httpRequest.headerField("Warning").isEmpty()) {
-
495 QDateTime dt; -
496 dt.setTime_t(current_age); -
497 if (dt.daysTo(currentDateTime) > 1)
-
498 httpRequest.setHeaderField("Warning", "113");
-
499 }
-
500 }
-
501 }
-
502 -
503 -
504 -
505 int freshness_lifetime = dateHeader.secsTo(expirationDate); -
506 response_is_fresh = (freshness_lifetime > current_age); -
507 } else {
-
508 -
509 response_is_fresh = currentDateTime.secsTo(expirationDate) >= 0; -
510 }
-
511 -
512 if (!response_is_fresh)
-
513 return false;
-
514 -
515 -
516 -
517 -
518 return sendCacheContents(metaData);
-
519} -
520 -
521QHttpNetworkRequest::Priority QNetworkReplyHttpImplPrivate::convert(const QNetworkRequest::Priority& prio) -
522{ -
523 switch (prio) { -
524 case QNetworkRequest::LowPriority: -
525 return QHttpNetworkRequest::LowPriority;
-
526 case QNetworkRequest::HighPriority: -
527 return QHttpNetworkRequest::HighPriority;
-
528 case QNetworkRequest::NormalPriority: -
529 default: -
530 return QHttpNetworkRequest::NormalPriority;
-
531 } -
532}
-
533 -
534void QNetworkReplyHttpImplPrivate::postRequest() -
535{ -
536 QNetworkReplyHttpImpl * const q = q_func(); -
537 -
538 QThread *thread = 0; -
539 if (synchronous) {
evaluated: synchronous
TRUEFALSE
yes
Evaluation Count:76
yes
Evaluation Count:636
76-636
540 -
541 thread = new QThread(); -
542 thread->setObjectName(QString::fromUtf8("" "httpReply" "", sizeof("httpReply") - 1)); -
543 QObject::connect(thread, "2""finished()", thread, "1""deleteLater()"); -
544 thread->start(); -
545 } else if (!managerPrivate->httpThread) {
evaluated: !managerPrivate->httpThread
TRUEFALSE
yes
Evaluation Count:436
yes
Evaluation Count:200
executed: }
Execution Count:76
76-436
546 -
547 -
548 managerPrivate->httpThread = new QThread(); -
549 managerPrivate->httpThread->setObjectName(QString::fromUtf8("" "httpThread" "", sizeof("httpThread") - 1)); -
550 managerPrivate->httpThread->start(); -
551 -
552 thread = managerPrivate->httpThread; -
553 } else {
executed: }
Execution Count:436
436
554 -
555 thread = managerPrivate->httpThread; -
556 }
executed: }
Execution Count:200
200
557 -
558 QUrl url = request.url(); -
559 httpRequest.setUrl(url); -
560 -
561 bool ssl = url.scheme().toLower() == QLatin1String("https"); -
562 q->setAttribute(QNetworkRequest::ConnectionEncryptedAttribute, ssl); -
563 httpRequest.setSsl(ssl); -
564 -
565 -
566 -
567 QNetworkProxy transparentProxy, cacheProxy; -
568 -
569 -
570 for (QForeachContainer<__typeof__(managerPrivate->queryProxy(QNetworkProxyQuery(request.url())))> _container_(managerPrivate->queryProxy(QNetworkProxyQuery(request.url()))); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QNetworkProxy &p = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
571 -
572 -
573 -
574 if (!ssl
evaluated: !ssl
TRUEFALSE
yes
Evaluation Count:625
yes
Evaluation Count:92
92-625
575 && (p.capabilities() & QNetworkProxy::CachingCapability)
evaluated: (p.capabilities() & QNetworkProxy::CachingCapability)
TRUEFALSE
yes
Evaluation Count:60
yes
Evaluation Count:565
60-565
576 && (p.type() == QNetworkProxy::HttpProxy ||
evaluated: p.type() == QNetworkProxy::HttpProxy
TRUEFALSE
yes
Evaluation Count:49
yes
Evaluation Count:11
11-49
577 p.type() == QNetworkProxy::HttpCachingProxy)) {
evaluated: p.type() == QNetworkProxy::HttpCachingProxy
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:3
3-8
578 cacheProxy = p; -
579 transparentProxy = QNetworkProxy::NoProxy; -
580 break;
executed: break;
Execution Count:57
57
581 } -
582 if (p.isTransparentProxy()) {
evaluated: p.isTransparentProxy()
TRUEFALSE
yes
Evaluation Count:652
yes
Evaluation Count:8
8-652
583 transparentProxy = p; -
584 cacheProxy = QNetworkProxy::NoProxy; -
585 break;
executed: break;
Execution Count:652
652
586 } -
587 }
executed: }
Execution Count:8
8
588 -
589 -
590 if (transparentProxy.type() == QNetworkProxy::DefaultProxy &&
evaluated: transparentProxy.type() == QNetworkProxy::DefaultProxy
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:709
3-709
591 cacheProxy.type() == QNetworkProxy::DefaultProxy) {
partially evaluated: cacheProxy.type() == QNetworkProxy::DefaultProxy
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-3
592 -
593 QMetaObject::invokeMethod(q, "_q_error", synchronous ? Qt::DirectConnection : Qt::QueuedConnection, -
594 QArgument<QNetworkReply::NetworkError >("QNetworkReply::NetworkError", QNetworkReply::ProxyNotFoundError), -
595 QArgument<QString >("QString", q->QNetworkReplyHttpImpl::tr("No suitable proxy found"))); -
596 QMetaObject::invokeMethod(q, "_q_finished", synchronous ? Qt::DirectConnection : Qt::QueuedConnection); -
597 return;
executed: return;
Execution Count:3
3
598 } -
599 -
600 -
601 -
602 bool loadedFromCache = false; -
603 httpRequest.setPriority(convert(request.priority())); -
604 -
605 switch (operation) { -
606 case QNetworkAccessManager::GetOperation: -
607 httpRequest.setOperation(QHttpNetworkRequest::Get); -
608 loadedFromCache = loadFromCacheIfAllowed(httpRequest); -
609 break;
executed: break;
Execution Count:493
493
610 -
611 case QNetworkAccessManager::HeadOperation: -
612 httpRequest.setOperation(QHttpNetworkRequest::Head); -
613 loadedFromCache = loadFromCacheIfAllowed(httpRequest); -
614 break;
executed: break;
Execution Count:26
26
615 -
616 case QNetworkAccessManager::PostOperation: -
617 invalidateCache(); -
618 httpRequest.setOperation(QHttpNetworkRequest::Post); -
619 createUploadByteDevice(); -
620 break;
executed: break;
Execution Count:142
142
621 -
622 case QNetworkAccessManager::PutOperation: -
623 invalidateCache(); -
624 httpRequest.setOperation(QHttpNetworkRequest::Put); -
625 createUploadByteDevice(); -
626 break;
executed: break;
Execution Count:35
35
627 -
628 case QNetworkAccessManager::DeleteOperation: -
629 invalidateCache(); -
630 httpRequest.setOperation(QHttpNetworkRequest::Delete); -
631 break;
executed: break;
Execution Count:7
7
632 -
633 case QNetworkAccessManager::CustomOperation: -
634 invalidateCache(); -
635 httpRequest.setOperation(QHttpNetworkRequest::Custom); -
636 createUploadByteDevice(); -
637 httpRequest.setCustomVerb(request.attribute( -
638 QNetworkRequest::CustomVerbAttribute).toByteArray()); -
639 break;
executed: break;
Execution Count:6
6
640 -
641 default: -
642 break;
never executed: break;
0
643 } -
644 -
645 if (loadedFromCache) {
evaluated: loadedFromCache
TRUEFALSE
yes
Evaluation Count:14
yes
Evaluation Count:695
14-695
646 return;
executed: return;
Execution Count:14
14
647 } -
648 -
649 QList<QByteArray> headers = request.rawHeaderList(); -
650 if (resumeOffset != 0) {
partially evaluated: resumeOffset != 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:695
0-695
651 if (headers.contains("Range")) {
never evaluated: headers.contains("Range")
0
652 -
653 -
654 headers.removeOne("Range"); -
655 -
656 -
657 QByteArray requestRange = request.rawHeader("Range").mid(6); -
658 -
659 int index = requestRange.indexOf('-'); -
660 -
661 quint64 requestStartOffset = requestRange.left(index).toULongLong(); -
662 quint64 requestEndOffset = requestRange.mid(index + 1).toULongLong(); -
663 -
664 requestRange = "bytes=" + QByteArray::number(resumeOffset + requestStartOffset) + -
665 '-' + QByteArray::number(requestEndOffset); -
666 -
667 httpRequest.setHeaderField("Range", requestRange); -
668 } else {
never executed: }
0
669 httpRequest.setHeaderField("Range", "bytes=" + QByteArray::number(resumeOffset) + '-'); -
670 }
never executed: }
0
671 } -
672 -
673 for (QForeachContainer<__typeof__(headers)> _container_(headers); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QByteArray &header = *_container_.i;; __extension__ ({--_container_.brk; break;})) -
674 httpRequest.setHeaderField(header, request.rawHeader(header));
executed: httpRequest.setHeaderField(header, request.rawHeader(header));
Execution Count:295
295
675 -
676 if (request.attribute(QNetworkRequest::HttpPipeliningAllowedAttribute).toBool() == true)
evaluated: request.attribute(QNetworkRequest::HttpPipeliningAllowedAttribute).toBool() == true
TRUEFALSE
yes
Evaluation Count:20
yes
Evaluation Count:675
20-675
677 httpRequest.setPipeliningAllowed(true);
executed: httpRequest.setPipeliningAllowed(true);
Execution Count:20
20
678 -
679 if (static_cast<QNetworkRequest::LoadControl> 1-694
680 (request.attribute(QNetworkRequest::AuthenticationReuseAttribute, 1-694
681 QNetworkRequest::Automatic).toInt()) == QNetworkRequest::Manual)
evaluated: static_cast<QNetworkRequest::LoadControl> (request.attribute(QNetworkRequest::AuthenticationReuseAttribute, QNetworkRequest::Automatic).toInt()) == QNetworkRequest::Manual
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:694
1-694
682 httpRequest.setWithCredentials(false);
executed: httpRequest.setWithCredentials(false);
Execution Count:1
1
683 -
684 -
685 -
686 QHttpThreadDelegate *delegate = new QHttpThreadDelegate; -
687 -
688 delegate->networkSession = managerPrivate->getNetworkSession(); -
689 -
690 -
691 -
692 -
693 QObject::connect(thread, "2""finished()", delegate, "1""deleteLater()"); -
694 -
695 -
696 delegate->httpRequest = httpRequest; -
697 -
698 delegate->cacheProxy = cacheProxy; -
699 delegate->transparentProxy = transparentProxy; -
700 -
701 delegate->ssl = ssl; -
702 -
703 if (ssl)
evaluated: ssl
TRUEFALSE
yes
Evaluation Count:87
yes
Evaluation Count:608
87-608
704 delegate->incomingSslConfiguration = request.sslConfiguration();
executed: delegate->incomingSslConfiguration = request.sslConfiguration();
Execution Count:87
87
705 -
706 -
707 -
708 delegate->synchronous = synchronous; -
709 -
710 -
711 -
712 delegate->authenticationManager = managerPrivate->authenticationManager; -
713 -
714 if (!synchronous) {
evaluated: !synchronous
TRUEFALSE
yes
Evaluation Count:619
yes
Evaluation Count:76
76-619
715 -
716 QVariant downloadBufferMaximumSizeAttribute = request.attribute(QNetworkRequest::MaximumDownloadBufferSizeAttribute); -
717 if (downloadBufferMaximumSizeAttribute.isValid()) {
evaluated: downloadBufferMaximumSizeAttribute.isValid()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:616
3-616
718 delegate->downloadBufferMaximumSize = downloadBufferMaximumSizeAttribute.toLongLong(); -
719 } else {
executed: }
Execution Count:3
3
720 -
721 -
722 -
723 delegate->downloadBufferMaximumSize = 128*1024; -
724 }
executed: }
Execution Count:616
616
725 -
726 -
727 -
728 delegate->pendingDownloadData = pendingDownloadDataEmissions; -
729 delegate->pendingDownloadProgress = pendingDownloadProgressEmissions; -
730 -
731 -
732 QObject::connect(delegate, "2""downloadData(QByteArray)", -
733 q, "1""replyDownloadData(QByteArray)", -
734 Qt::QueuedConnection); -
735 QObject::connect(delegate, "2""downloadFinished()", -
736 q, "1""replyFinished()", -
737 Qt::QueuedConnection); -
738 QObject::connect(delegate, "2""downloadMetaData(QList<QPair<QByteArray,QByteArray> >,int,QString,bool,QSharedPointer<char>,qint64)", -
739 q, "1""replyDownloadMetaData(QList<QPair<QByteArray,QByteArray> >,int,QString,bool,QSharedPointer<char>,qint64)", -
740 Qt::QueuedConnection); -
741 QObject::connect(delegate, "2""downloadProgress(qint64,qint64)", -
742 q, "1""replyDownloadProgressSlot(qint64,qint64)", -
743 Qt::QueuedConnection); -
744 QObject::connect(delegate, "2""error(QNetworkReply::NetworkError,QString)", -
745 q, "1""httpError(QNetworkReply::NetworkError,QString)", -
746 Qt::QueuedConnection); -
747 -
748 QObject::connect(delegate, "2""sslConfigurationChanged(QSslConfiguration)", -
749 q, "1""replySslConfigurationChanged(QSslConfiguration)", -
750 Qt::QueuedConnection); -
751 -
752 -
753 QObject::connect(delegate, "2""authenticationRequired(QHttpNetworkRequest,QAuthenticator*)", -
754 q, "1""httpAuthenticationRequired(QHttpNetworkRequest,QAuthenticator*)", -
755 Qt::BlockingQueuedConnection); -
756 -
757 QObject::connect(delegate, "2""proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)", -
758 q, "1""proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)", -
759 Qt::BlockingQueuedConnection); -
760 -
761 -
762 QObject::connect(delegate, "2""sslErrors(QList<QSslError>,bool*,QList<QSslError>*)", -
763 q, "1""replySslErrors(QList<QSslError>,bool*,QList<QSslError>*)", -
764 Qt::BlockingQueuedConnection); -
765 -
766 -
767 QObject::connect(q, "2""startHttpRequest()", delegate, "1""startRequest()"); -
768 QObject::connect(q, "2""abortHttpRequest()", delegate, "1""abortRequest()"); -
769 -
770 -
771 QObject::connect(q, "2""readBufferSizeChanged(qint64)", delegate, "1""readBufferSizeChanged(qint64)"); -
772 QObject::connect(q, "2""readBufferFreed(qint64)", delegate, "1""readBufferFreed(qint64)"); -
773 -
774 if (uploadByteDevice) {
evaluated: uploadByteDevice
TRUEFALSE
yes
Evaluation Count:138
yes
Evaluation Count:481
138-481
775 QNonContiguousByteDeviceThreadForwardImpl *forwardUploadDevice = -
776 new QNonContiguousByteDeviceThreadForwardImpl(uploadByteDevice->atEnd(), uploadByteDevice->size()); -
777 if (uploadByteDevice->isResetDisabled())
evaluated: uploadByteDevice->isResetDisabled()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:137
1-137
778 forwardUploadDevice->disableReset();
executed: forwardUploadDevice->disableReset();
Execution Count:1
1
779 forwardUploadDevice->setParent(delegate); -
780 delegate->httpRequest.setUploadByteDevice(forwardUploadDevice); -
781 -
782 -
783 QObject::connect(q, "2""haveUploadData(QByteArray,bool,qint64)", -
784 forwardUploadDevice, "1""haveDataSlot(QByteArray,bool,qint64)", Qt::QueuedConnection); -
785 QObject::connect(uploadByteDevice.data(), "2""readyRead()", -
786 forwardUploadDevice, "2""readyRead()", -
787 Qt::QueuedConnection); -
788 -
789 -
790 QObject::connect(forwardUploadDevice, "2""wantData(qint64)", -
791 q, "1""wantUploadDataSlot(qint64)"); -
792 QObject::connect(forwardUploadDevice, "2""processedData(qint64)", -
793 q, "1""sentUploadDataSlot(qint64)"); -
794 QObject::connect(forwardUploadDevice, "2""resetData(bool*)", -
795 q, "1""resetUploadDataSlot(bool*)", -
796 Qt::BlockingQueuedConnection); -
797 }
executed: }
Execution Count:138
138
798 } else if (synchronous) {
executed: }
Execution Count:619
partially evaluated: synchronous
TRUEFALSE
yes
Evaluation Count:76
no
Evaluation Count:0
0-619
799 QObject::connect(q, "2""startHttpRequestSynchronously()", delegate, "1""startRequestSynchronously()", Qt::BlockingQueuedConnection); -
800 -
801 if (uploadByteDevice) {
evaluated: uploadByteDevice
TRUEFALSE
yes
Evaluation Count:41
yes
Evaluation Count:35
35-41
802 -
803 -
804 -
805 -
806 -
807 -
808 delegate->httpRequest.setUploadByteDevice(uploadByteDevice.data()); -
809 }
executed: }
Execution Count:41
41
810 }
executed: }
Execution Count:76
76
811 -
812 -
813 -
814 delegate->moveToThread(thread); -
815 -
816 -
817 -
818 downloadProgressSignalChoke.start(); -
819 uploadProgressSignalChoke.invalidate(); -
820 -
821 -
822 if (synchronous) {
evaluated: synchronous
TRUEFALSE
yes
Evaluation Count:76
yes
Evaluation Count:619
76-619
823 q->startHttpRequestSynchronously(); -
824 -
825 if (delegate->incomingErrorCode != QNetworkReply::NoError) {
evaluated: delegate->incomingErrorCode != QNetworkReply::NoError
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:63
13-63
826 replyDownloadMetaData -
827 (delegate->incomingHeaders, -
828 delegate->incomingStatusCode, -
829 delegate->incomingReasonPhrase, -
830 delegate->isPipeliningUsed, -
831 QSharedPointer<char>(), -
832 delegate->incomingContentLength); -
833 replyDownloadData(delegate->synchronousDownloadData); -
834 httpError(delegate->incomingErrorCode, delegate->incomingErrorDetail); -
835 } else {
executed: }
Execution Count:13
13
836 replyDownloadMetaData -
837 (delegate->incomingHeaders, -
838 delegate->incomingStatusCode, -
839 delegate->incomingReasonPhrase, -
840 delegate->isPipeliningUsed, -
841 QSharedPointer<char>(), -
842 delegate->incomingContentLength); -
843 replyDownloadData(delegate->synchronousDownloadData); -
844 }
executed: }
Execution Count:63
63
845 -
846 thread->quit(); -
847 thread->wait(5000); -
848 if (thread->isFinished())
partially evaluated: thread->isFinished()
TRUEFALSE
yes
Evaluation Count:76
no
Evaluation Count:0
0-76
849 delete thread;
executed: delete thread;
Execution Count:76
76
850 else -
851 QObject::connect(thread, "2""finished()", thread, "1""deleteLater()");
never executed: QObject::connect(thread, "2""finished()", thread, "1""deleteLater()");
0
852 -
853 finished(); -
854 } else {
executed: }
Execution Count:76
76
855 q->startHttpRequest(); -
856 }
executed: }
Execution Count:619
619
857} -
858 -
859void QNetworkReplyHttpImplPrivate::invalidateCache() -
860{ -
861 QAbstractNetworkCache *nc = managerPrivate->networkCache; -
862 if (nc)
-
863 nc->remove(request.url());
-
864}
-
865 -
866void QNetworkReplyHttpImplPrivate::initCacheSaveDevice() -
867{ -
868 QNetworkReplyHttpImpl * const q = q_func(); -
869 -
870 -
871 -
872 if (q->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 206) {
-
873 cacheEnabled = false; -
874 return;
-
875 } -
876 -
877 -
878 QNetworkCacheMetaData metaData; -
879 metaData.setUrl(url); -
880 metaData = fetchCacheMetaData(metaData); -
881 -
882 -
883 QVariant redirectionTarget = q->attribute(QNetworkRequest::RedirectionTargetAttribute); -
884 if (redirectionTarget.isValid()) {
-
885 QNetworkCacheMetaData::AttributesMap attributes = metaData.attributes(); -
886 attributes.insert(QNetworkRequest::RedirectionTargetAttribute, redirectionTarget); -
887 metaData.setAttributes(attributes); -
888 }
-
889 -
890 cacheSaveDevice = managerPrivate->networkCache->prepare(metaData); -
891 -
892 if (!cacheSaveDevice || (cacheSaveDevice && !cacheSaveDevice->isOpen())) {
-
893 if (cacheSaveDevice && !cacheSaveDevice->isOpen())
-
894 QMessageLogger("access/qnetworkreplyhttpimpl.cpp", 965, __PRETTY_FUNCTION__).critical("QNetworkReplyImpl: network cache returned a device that is not open -- " -
895 "class %s probably needs to be fixed", -
896 managerPrivate->networkCache->metaObject()->className());
-
897 -
898 managerPrivate->networkCache->remove(url); -
899 cacheSaveDevice = 0; -
900 cacheEnabled = false; -
901 }
-
902}
-
903 -
904void QNetworkReplyHttpImplPrivate::replyDownloadData(QByteArray d) -
905{ -
906 QNetworkReplyHttpImpl * const q = q_func(); -
907 -
908 -
909 if (!q->isOpen())
-
910 return;
-
911 -
912 int pendingSignals = (int)pendingDownloadDataEmissions->fetchAndAddAcquire(-1) - 1; -
913 -
914 if (pendingSignals > 0) {
-
915 -
916 -
917 -
918 -
919 pendingDownloadData.append(d); -
920 return;
-
921 } -
922 -
923 pendingDownloadData.append(d); -
924 d.clear(); -
925 -
926 -
927 -
928 -
929 QByteDataBuffer pendingDownloadDataCopy = pendingDownloadData; -
930 pendingDownloadData.clear(); -
931 -
932 if (cacheEnabled && isCachingAllowed() && !cacheSaveDevice) {
-
933 initCacheSaveDevice(); -
934 }
-
935 -
936 qint64 bytesWritten = 0; -
937 for (int i = 0; i < pendingDownloadDataCopy.bufferCount(); i++) {
-
938 QByteArray const &item = pendingDownloadDataCopy[i]; -
939 -
940 if (cacheSaveDevice)
-
941 cacheSaveDevice->write(item.constData(), item.size());
-
942 downloadMultiBuffer.append(item); -
943 -
944 bytesWritten += item.size(); -
945 }
-
946 pendingDownloadDataCopy.clear(); -
947 -
948 bytesDownloaded += bytesWritten; -
949 -
950 -
951 QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); -
952 if (preMigrationDownloaded != static_cast<long long>(-1LL))
-
953 totalSize = totalSize.toLongLong() + preMigrationDownloaded;
-
954 -
955 q->readyRead(); -
956 -
957 -
958 if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval) {
-
959 downloadProgressSignalChoke.restart(); -
960 q->downloadProgress(bytesDownloaded, -
961 totalSize.isNull() ? static_cast<long long>(-1LL) : totalSize.toLongLong()); -
962 }
-
963 -
964}
-
965 -
966void QNetworkReplyHttpImplPrivate::replyFinished() -
967{ -
968 -
969 -
970 if (loadingFromCache)
-
971 return;
-
972 -
973 finished(); -
974}
-
975 -
976void QNetworkReplyHttpImplPrivate::checkForRedirect(const int statusCode) -
977{ -
978 QNetworkReplyHttpImpl * const q = q_func(); -
979 switch (statusCode) { -
980 case 301: -
981 case 302: -
982 case 303: -
983 case 307: -
984 -
985 -
986 -
987 QByteArray header = q->rawHeader("location"); -
988 QUrl url = QUrl(QString::fromUtf8(header)); -
989 if (!url.isValid())
-
990 url = QUrl(QLatin1String(header));
-
991 q->setAttribute(QNetworkRequest::RedirectionTargetAttribute, url); -
992 }
-
993}
-
994 -
995void QNetworkReplyHttpImplPrivate::replyDownloadMetaData -
996 (QList<QPair<QByteArray,QByteArray> > hm, -
997 int sc,QString rp,bool pu, -
998 QSharedPointer<char> db, -
999 qint64 contentLength) -
1000{ -
1001 QNetworkReplyHttpImpl * const q = q_func(); -
1002 (void)contentLength;; -
1003 -
1004 statusCode = sc; -
1005 reasonPhrase = rp; -
1006 -
1007 -
1008 if (!db.isNull()) {
-
1009 downloadBufferPointer = db; -
1010 downloadZerocopyBuffer = downloadBufferPointer.data(); -
1011 downloadBufferCurrentSize = 0; -
1012 q->setAttribute(QNetworkRequest::DownloadBufferAttribute, QVariant::fromValue<QSharedPointer<char> > (downloadBufferPointer)); -
1013 }
-
1014 -
1015 q->setAttribute(QNetworkRequest::HttpPipeliningWasUsedAttribute, pu); -
1016 -
1017 -
1018 QList<QPair<QByteArray, QByteArray> > headerMap = hm; -
1019 QList<QPair<QByteArray, QByteArray> >::ConstIterator it = headerMap.constBegin(), -
1020 end = headerMap.constEnd(); -
1021 for (; it != end; ++it) {
-
1022 QByteArray value = q->rawHeader(it->first); -
1023 if (!value.isEmpty()) {
-
1024 if (qstricmp(it->first.constData(), "set-cookie") == 0)
-
1025 value += '\n';
-
1026 else -
1027 value += ", ";
-
1028 } -
1029 value += it->second; -
1030 q->setRawHeader(it->first, value); -
1031 }
-
1032 -
1033 q->setAttribute(QNetworkRequest::HttpStatusCodeAttribute, statusCode); -
1034 q->setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, reasonPhrase); -
1035 -
1036 -
1037 checkForRedirect(statusCode); -
1038 -
1039 if (statusCode >= 500 && statusCode < 600) {
-
1040 QAbstractNetworkCache *nc = managerPrivate->networkCache; -
1041 if (nc) {
-
1042 QNetworkCacheMetaData metaData = nc->metaData(request.url()); -
1043 QNetworkHeadersPrivate cacheHeaders; -
1044 cacheHeaders.setAllRawHeaders(metaData.rawHeaders()); -
1045 QNetworkHeadersPrivate::RawHeadersList::ConstIterator it; -
1046 it = cacheHeaders.findRawHeader("Cache-Control"); -
1047 bool mustReValidate = false; -
1048 if (it != cacheHeaders.rawHeaders.constEnd()) {
-
1049 QHash<QByteArray, QByteArray> cacheControl = parseHttpOptionHeader(it->second); -
1050 if (cacheControl.contains("must-revalidate"))
-
1051 mustReValidate = true;
-
1052 }
-
1053 if (!mustReValidate && sendCacheContents(metaData))
-
1054 return;
-
1055 }
-
1056 }
-
1057 -
1058 if (statusCode == 304) {
-
1059 -
1060 -
1061 -
1062 QAbstractNetworkCache *nc = managerPrivate->networkCache; -
1063 if (nc) {
-
1064 QNetworkCacheMetaData oldMetaData = nc->metaData(request.url()); -
1065 QNetworkCacheMetaData metaData = fetchCacheMetaData(oldMetaData); -
1066 if (oldMetaData != metaData)
-
1067 nc->updateMetaData(metaData);
-
1068 if (sendCacheContents(metaData))
-
1069 return;
-
1070 }
-
1071 }
-
1072 -
1073 -
1074 if (statusCode != 304 && statusCode != 303) {
-
1075 if (!isCachingEnabled())
-
1076 setCachingEnabled(true);
-
1077 }
-
1078 -
1079 metaDataChanged(); -
1080}
-
1081 -
1082void QNetworkReplyHttpImplPrivate::replyDownloadProgressSlot(qint64 bytesReceived, qint64 bytesTotal) -
1083{ -
1084 QNetworkReplyHttpImpl * const q = q_func(); -
1085 -
1086 -
1087 if (!q->isOpen())
-
1088 return;
-
1089 -
1090 -
1091 -
1092 int pendingSignals = (int)pendingDownloadProgressEmissions->fetchAndAddAcquire(-1) - 1; -
1093 if (pendingSignals > 0) {
-
1094 -
1095 -
1096 return;
-
1097 } -
1098 -
1099 if (!q->isOpen())
-
1100 return;
-
1101 -
1102 if (cacheEnabled && isCachingAllowed() && bytesReceived == bytesTotal) {
-
1103 -
1104 initCacheSaveDevice(); -
1105 -
1106 if (cacheSaveDevice && cacheEnabled)
-
1107 cacheSaveDevice->write(downloadZerocopyBuffer, bytesTotal);
-
1108 -
1109 }
-
1110 -
1111 bytesDownloaded = bytesReceived; -
1112 -
1113 downloadBufferCurrentSize = bytesReceived; -
1114 -
1115 -
1116 -
1117 -
1118 if (bytesDownloaded > 0)
-
1119 q->readyRead();
-
1120 if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval) {
-
1121 downloadProgressSignalChoke.restart(); -
1122 q->downloadProgress(bytesDownloaded, bytesTotal); -
1123 }
-
1124}
-
1125 -
1126void QNetworkReplyHttpImplPrivate::httpAuthenticationRequired(const QHttpNetworkRequest &request, -
1127 QAuthenticator *auth) -
1128{ -
1129 managerPrivate->authenticationRequired(auth, q_func(), synchronous, url, &urlForLastAuthentication, request.withCredentials()); -
1130}
-
1131 -
1132 -
1133void QNetworkReplyHttpImplPrivate::proxyAuthenticationRequired(const QNetworkProxy &proxy, -
1134 QAuthenticator *authenticator) -
1135{ -
1136 managerPrivate->proxyAuthenticationRequired(proxy, synchronous, authenticator, &lastProxyAuthentication); -
1137}
-
1138 -
1139 -
1140void QNetworkReplyHttpImplPrivate::httpError(QNetworkReply::NetworkError errorCode, -
1141 const QString &errorString) -
1142{ -
1143 -
1144 -
1145 -
1146 -
1147 -
1148 error(errorCode, errorString); -
1149}
-
1150 -
1151 -
1152void QNetworkReplyHttpImplPrivate::replySslErrors( -
1153 const QList<QSslError> &list, bool *ignoreAll, QList<QSslError> *toBeIgnored) -
1154{ -
1155 QNetworkReplyHttpImpl * const q = q_func(); -
1156 q->sslErrors(list); -
1157 -
1158 if (pendingIgnoreAllSslErrors)
-
1159 *ignoreAll = true;
-
1160 if (!pendingIgnoreSslErrorsList.isEmpty())
-
1161 *toBeIgnored = pendingIgnoreSslErrorsList;
-
1162}
-
1163 -
1164void QNetworkReplyHttpImplPrivate::replySslConfigurationChanged(const QSslConfiguration &sslConfiguration) -
1165{ -
1166 -
1167 this->sslConfiguration = sslConfiguration; -
1168}
-
1169 -
1170 -
1171 -
1172void QNetworkReplyHttpImplPrivate::resetUploadDataSlot(bool *r) -
1173{ -
1174 *r = uploadByteDevice->reset(); -
1175}
-
1176 -
1177 -
1178void QNetworkReplyHttpImplPrivate::sentUploadDataSlot(qint64 amount) -
1179{ -
1180 uploadByteDevice->advanceReadPointer(amount); -
1181}
-
1182 -
1183 -
1184void QNetworkReplyHttpImplPrivate::wantUploadDataSlot(qint64 maxSize) -
1185{ -
1186 QNetworkReplyHttpImpl * const q = q_func(); -
1187 -
1188 -
1189 qint64 currentUploadDataLength = 0; -
1190 char *data = const_cast<char*>(uploadByteDevice->readPointer(maxSize, currentUploadDataLength)); -
1191 -
1192 QByteArray dataArray(data, currentUploadDataLength); -
1193 -
1194 -
1195 q->haveUploadData(dataArray, uploadByteDevice->atEnd(), uploadByteDevice->size()); -
1196}
-
1197 -
1198 -
1199 -
1200 -
1201bool QNetworkReplyHttpImplPrivate::sendCacheContents(const QNetworkCacheMetaData &metaData) -
1202{ -
1203 QNetworkReplyHttpImpl * const q = q_func(); -
1204 -
1205 setCachingEnabled(false); -
1206 if (!metaData.isValid())
-
1207 return false;
-
1208 -
1209 QAbstractNetworkCache *nc = managerPrivate->networkCache; -
1210 qt_noop(); -
1211 QIODevice *contents = nc->data(url); -
1212 if (!contents) {
-
1213 -
1214 -
1215 -
1216 return false;
-
1217 } -
1218 contents->setParent(q); -
1219 -
1220 QNetworkCacheMetaData::AttributesMap attributes = metaData.attributes(); -
1221 int status = attributes.value(QNetworkRequest::HttpStatusCodeAttribute).toInt(); -
1222 if (status < 100)
-
1223 status = 200;
-
1224 -
1225 q->setAttribute(QNetworkRequest::HttpStatusCodeAttribute, status); -
1226 q->setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, attributes.value(QNetworkRequest::HttpReasonPhraseAttribute)); -
1227 q->setAttribute(QNetworkRequest::SourceIsFromCacheAttribute, true); -
1228 -
1229 QNetworkCacheMetaData::RawHeaderList rawHeaders = metaData.rawHeaders(); -
1230 QNetworkCacheMetaData::RawHeaderList::ConstIterator it = rawHeaders.constBegin(), -
1231 end = rawHeaders.constEnd(); -
1232 for ( ; it != end; ++it)
-
1233 setRawHeader(it->first, it->second);
-
1234 -
1235 checkForRedirect(status); -
1236 -
1237 cacheLoadDevice = contents; -
1238 q->connect(cacheLoadDevice, "2""readyRead()", "1""_q_cacheLoadReadyRead()"); -
1239 q->connect(cacheLoadDevice, "2""readChannelFinished()", "1""_q_cacheLoadReadyRead()"); -
1240 -
1241 -
1242 -
1243 -
1244 QMetaObject::invokeMethod(q, "metaDataChanged", Qt::QueuedConnection); -
1245 QMetaObject::invokeMethod(q, "_q_cacheLoadReadyRead", Qt::QueuedConnection); -
1246 loadingFromCache = true; -
1247 return true;
-
1248} -
1249 -
1250QNetworkCacheMetaData QNetworkReplyHttpImplPrivate::fetchCacheMetaData(const QNetworkCacheMetaData &oldMetaData) const -
1251{ -
1252 const QNetworkReplyHttpImpl * const q = q_func(); -
1253 -
1254 QNetworkCacheMetaData metaData = oldMetaData; -
1255 -
1256 QNetworkHeadersPrivate cacheHeaders; -
1257 cacheHeaders.setAllRawHeaders(metaData.rawHeaders()); -
1258 QNetworkHeadersPrivate::RawHeadersList::ConstIterator it; -
1259 -
1260 QList<QByteArray> newHeaders = q->rawHeaderList(); -
1261 for (QForeachContainer<__typeof__(newHeaders)> _container_(newHeaders); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QByteArray header = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
1262 QByteArray originalHeader = header; -
1263 header = header.toLower(); -
1264 bool hop_by_hop = -
1265 (header == "connection"
-
1266 || header == "keep-alive"
-
1267 || header == "proxy-authenticate"
-
1268 || header == "proxy-authorization"
-
1269 || header == "te"
-
1270 || header == "trailers"
-
1271 || header == "transfer-encoding"
-
1272 || header == "upgrade");
-
1273 if (hop_by_hop)
-
1274 continue;
-
1275 if (header == "warning") {
-
1276 QByteArray v = q->rawHeader(header); -
1277 if (v.length() == 3
-
1278 && v[0] == '1'
-
1279 && v[1] >= '0' && v[1] <= '9'
-
1280 && v[2] >= '0' && v[2] <= '9')
-
1281 continue;
-
1282 }
-
1283 -
1284 it = cacheHeaders.findRawHeader(header); -
1285 if (it != cacheHeaders.rawHeaders.constEnd()) {
-
1286 -
1287 if (header == "content-encoding"
-
1288 || header == "content-range"
-
1289 || header == "content-type")
-
1290 continue;
-
1291 -
1292 -
1293 -
1294 if (header == "content-length")
-
1295 continue;
-
1296 }
-
1297 cacheHeaders.setRawHeader(originalHeader, q->rawHeader(header)); -
1298 }
-
1299 metaData.setRawHeaders(cacheHeaders.rawHeaders); -
1300 -
1301 bool checkExpired = true; -
1302 -
1303 QHash<QByteArray, QByteArray> cacheControl; -
1304 it = cacheHeaders.findRawHeader("Cache-Control"); -
1305 if (it != cacheHeaders.rawHeaders.constEnd()) {
-
1306 cacheControl = parseHttpOptionHeader(it->second); -
1307 QByteArray maxAge = cacheControl.value("max-age"); -
1308 if (!maxAge.isEmpty()) {
-
1309 checkExpired = false; -
1310 QDateTime dt = QDateTime::currentDateTime(); -
1311 dt = dt.addSecs(maxAge.toInt()); -
1312 metaData.setExpirationDate(dt); -
1313 }
-
1314 }
-
1315 if (checkExpired) {
-
1316 it = cacheHeaders.findRawHeader("expires"); -
1317 if (it != cacheHeaders.rawHeaders.constEnd()) {
-
1318 QDateTime expiredDateTime = QNetworkHeadersPrivate::fromHttpDate(it->second); -
1319 metaData.setExpirationDate(expiredDateTime); -
1320 }
-
1321 }
-
1322 -
1323 it = cacheHeaders.findRawHeader("last-modified"); -
1324 if (it != cacheHeaders.rawHeaders.constEnd())
-
1325 metaData.setLastModified(QNetworkHeadersPrivate::fromHttpDate(it->second));
-
1326 -
1327 bool canDiskCache; -
1328 -
1329 -
1330 if (httpRequest.operation() == QHttpNetworkRequest::Get) {
-
1331 -
1332 canDiskCache = true; -
1333 -
1334 -
1335 -
1336 it = cacheHeaders.findRawHeader("pragma"); -
1337 if (it != cacheHeaders.rawHeaders.constEnd()
-
1338 && it->second == "no-cache")
-
1339 canDiskCache = false;
-
1340 -
1341 -
1342 if (cacheControl.contains("no-cache"))
-
1343 canDiskCache = false;
-
1344 else if (cacheControl.contains("no-store"))
-
1345 canDiskCache = false;
-
1346 -
1347 -
1348 } else if (httpRequest.operation() == QHttpNetworkRequest::Post) {
-
1349 -
1350 canDiskCache = false; -
1351 -
1352 -
1353 if (cacheControl.contains("max-age"))
-
1354 canDiskCache = true;
-
1355 -
1356 -
1357 } else {
-
1358 canDiskCache = false; -
1359 }
-
1360 -
1361 metaData.setSaveToDisk(canDiskCache); -
1362 QNetworkCacheMetaData::AttributesMap attributes; -
1363 if (statusCode != 304) {
-
1364 -
1365 attributes.insert(QNetworkRequest::HttpStatusCodeAttribute, statusCode); -
1366 attributes.insert(QNetworkRequest::HttpReasonPhraseAttribute, reasonPhrase); -
1367 } else {
-
1368 -
1369 attributes = oldMetaData.attributes(); -
1370 }
-
1371 metaData.setAttributes(attributes); -
1372 return metaData;
-
1373} -
1374 -
1375bool QNetworkReplyHttpImplPrivate::canResume() const -
1376{ -
1377 const QNetworkReplyHttpImpl * const q = q_func(); -
1378 -
1379 -
1380 if (operation != QNetworkAccessManager::GetOperation)
-
1381 return false;
-
1382 -
1383 -
1384 QByteArray acceptRangesheaderName("Accept-Ranges"); -
1385 if (!q->hasRawHeader(acceptRangesheaderName) || q->rawHeader(acceptRangesheaderName) == "none")
-
1386 return false;
-
1387 -
1388 -
1389 if (request.hasRawHeader("Range")) {
-
1390 QByteArray range = request.rawHeader("Range"); -
1391 if (!range.startsWith("bytes="))
-
1392 return false;
-
1393 }
-
1394 -
1395 -
1396 -
1397 if (downloadZerocopyBuffer)
-
1398 return false;
-
1399 -
1400 return true;
-
1401} -
1402 -
1403void QNetworkReplyHttpImplPrivate::setResumeOffset(quint64 offset) -
1404{ -
1405 resumeOffset = offset; -
1406}
-
1407 -
1408 -
1409 -
1410 -
1411 -
1412 -
1413bool QNetworkReplyHttpImplPrivate::start() -
1414{ -
1415 -
1416 QSharedPointer<QNetworkSession> networkSession(managerPrivate->getNetworkSession()); -
1417 if (!networkSession) {
-
1418 -
1419 postRequest(); -
1420 return true;
-
1421 -
1422 } -
1423 -
1424 -
1425 const QString host = url.host(); -
1426 if (host == QLatin1String("localhost") ||
-
1427 QHostAddress(host).isLoopback()) {
-
1428 -
1429 postRequest(); -
1430 return true;
-
1431 } -
1432 -
1433 if (networkSession->isOpen() &&
-
1434 networkSession->state() == QNetworkSession::Connected) {
-
1435 QNetworkReplyHttpImpl * const q = q_func(); -
1436 QObject::connect(networkSession.data(), "2""usagePoliciesChanged(QNetworkSession::UsagePolicies)", -
1437 q, "1""_q_networkSessionUsagePoliciesChanged(QNetworkSession::UsagePolicies)"); -
1438 postRequest(); -
1439 return true;
-
1440 } -
1441 -
1442 return false;
-
1443 -
1444} -
1445 -
1446void QNetworkReplyHttpImplPrivate::_q_startOperation() -
1447{ -
1448 QNetworkReplyHttpImpl * const q = q_func(); -
1449 -
1450 -
1451 if (state == Working) {
-
1452 QMessageLogger("access/qnetworkreplyhttpimpl.cpp", 1554, __PRETTY_FUNCTION__).debug("QNetworkReplyImpl::_q_startOperation was called more than once"); -
1453 return;
-
1454 } -
1455 state = Working; -
1456 -
1457 -
1458 -
1459 QSharedPointer<QNetworkSession> session(manager->d_func()->getNetworkSession()); -
1460 QVariant isBackground = request.attribute(QNetworkRequest::BackgroundRequestAttribute, QVariant::fromValue(false)); -
1461 if (isBackground.toBool() && session && session->usagePolicies().testFlag(QNetworkSession::NoBackgroundTrafficPolicy)) {
-
1462 QMetaObject::invokeMethod(q, "_q_error", synchronous ? Qt::DirectConnection : Qt::QueuedConnection, -
1463 QArgument<QNetworkReply::NetworkError >("QNetworkReply::NetworkError", QNetworkReply::BackgroundRequestNotAllowedError), -
1464 QArgument<QString >("QString", QCoreApplication::translate("QNetworkReply", "Background request not allowed."))); -
1465 QMetaObject::invokeMethod(q, "_q_finished", synchronous ? Qt::DirectConnection : Qt::QueuedConnection); -
1466 return;
-
1467 } -
1468 -
1469 -
1470 if (!start()) {
-
1471 -
1472 -
1473 -
1474 -
1475 state = WaitingForSession; -
1476 -
1477 if (session) {
-
1478 QObject::connect(session.data(), "2""error(QNetworkSession::SessionError)", -
1479 q, "1""_q_networkSessionFailed()", Qt::QueuedConnection); -
1480 -
1481 if (!session->isOpen()) {
-
1482 session->setSessionProperty(QString::fromUtf8("" "ConnectInBackground" "", sizeof("ConnectInBackground") - 1), isBackground); -
1483 session->open(); -
1484 }
-
1485 } else {
-
1486 QMessageLogger("access/qnetworkreplyhttpimpl.cpp", 1588, __PRETTY_FUNCTION__).warning("Backend is waiting for QNetworkSession to connect, but there is none!"); -
1487 QMetaObject::invokeMethod(q, "_q_error", synchronous ? Qt::DirectConnection : Qt::QueuedConnection, -
1488 QArgument<QNetworkReply::NetworkError >("QNetworkReply::NetworkError", QNetworkReply::NetworkSessionFailedError), -
1489 QArgument<QString >("QString", QCoreApplication::translate("QNetworkReply", "Network session error."))); -
1490 QMetaObject::invokeMethod(q, "_q_finished", synchronous ? Qt::DirectConnection : Qt::QueuedConnection); -
1491 return;
-
1492 } -
1493 } -
1494 -
1495 if (synchronous) {
-
1496 state = Finished; -
1497 q_func()->setFinished(true); -
1498 } else {
-
1499 if (state != Finished) {
-
1500 -
1501 }
-
1502 }
-
1503} -
1504 -
1505void QNetworkReplyHttpImplPrivate::_q_cacheLoadReadyRead() -
1506{ -
1507 QNetworkReplyHttpImpl * const q = q_func(); -
1508 -
1509 if (state != Working)
-
1510 return;
-
1511 if (!cacheLoadDevice || !q->isOpen() || !cacheLoadDevice->bytesAvailable())
-
1512 return;
-
1513 -
1514 -
1515 -
1516 -
1517 -
1518 -
1519 QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); -
1520 -
1521 -
1522 -
1523 -
1524 -
1525 q->readyRead(); -
1526 if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval) {
-
1527 downloadProgressSignalChoke.restart(); -
1528 q->downloadProgress(bytesDownloaded, -
1529 totalSize.isNull() ? static_cast<long long>(-1LL) : totalSize.toLongLong()); -
1530 }
-
1531 -
1532 -
1533 -
1534 -
1535 while (cacheLoadDevice->bytesAvailable()) {
-
1536 downloadMultiBuffer.append(cacheLoadDevice->readAll()); -
1537 }
-
1538 -
1539 if (cacheLoadDevice->isSequential()) {
-
1540 -
1541 char c; -
1542 qint64 actualCount = cacheLoadDevice->read(&c, 1); -
1543 if (actualCount < 0) {
-
1544 cacheLoadDevice->deleteLater(); -
1545 cacheLoadDevice = 0; -
1546 QMetaObject::invokeMethod(q, "_q_finished", Qt::QueuedConnection); -
1547 } else if (actualCount == 1) {
-
1548 -
1549 -
1550 cacheLoadDevice->ungetChar(c); -
1551 }
-
1552 } else if ((!cacheLoadDevice->isSequential() && cacheLoadDevice->atEnd())) {
-
1553 -
1554 cacheLoadDevice->deleteLater(); -
1555 cacheLoadDevice = 0; -
1556 QMetaObject::invokeMethod(q, "_q_finished", Qt::QueuedConnection); -
1557 }
-
1558 -
1559} -
1560 -
1561 -
1562void QNetworkReplyHttpImplPrivate::_q_bufferOutgoingDataFinished() -
1563{ -
1564 QNetworkReplyHttpImpl * const q = q_func(); -
1565 -
1566 -
1567 -
1568 if (state != Buffering)
-
1569 return;
-
1570 -
1571 -
1572 QObject::disconnect(outgoingData, "2""readyRead()", q, "1""_q_bufferOutgoingData()"); -
1573 QObject::disconnect(outgoingData, "2""readChannelFinished()", q, "1""_q_bufferOutgoingDataFinished()"); -
1574 -
1575 -
1576 QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); -
1577}
-
1578 -
1579void QNetworkReplyHttpImplPrivate::_q_bufferOutgoingData() -
1580{ -
1581 QNetworkReplyHttpImpl * const q = q_func(); -
1582 -
1583 if (!outgoingDataBuffer) {
-
1584 -
1585 outgoingDataBuffer = QSharedPointer<QRingBuffer>(new QRingBuffer()); -
1586 -
1587 QObject::connect(outgoingData, "2""readyRead()", q, "1""_q_bufferOutgoingData()"); -
1588 QObject::connect(outgoingData, "2""readChannelFinished()", q, "1""_q_bufferOutgoingDataFinished()"); -
1589 }
-
1590 -
1591 qint64 bytesBuffered = 0; -
1592 qint64 bytesToBuffer = 0; -
1593 -
1594 -
1595 for(;;) { -
1596 bytesToBuffer = outgoingData->bytesAvailable(); -
1597 -
1598 if (bytesToBuffer <= 0)
-
1599 bytesToBuffer = 2*1024;
-
1600 -
1601 char *dst = outgoingDataBuffer->reserve(bytesToBuffer); -
1602 bytesBuffered = outgoingData->read(dst, bytesToBuffer); -
1603 -
1604 if (bytesBuffered == -1) {
-
1605 -
1606 outgoingDataBuffer->chop(bytesToBuffer); -
1607 -
1608 _q_bufferOutgoingDataFinished(); -
1609 break;
-
1610 } else if (bytesBuffered == 0) {
-
1611 -
1612 outgoingDataBuffer->chop(bytesToBuffer); -
1613 -
1614 break;
-
1615 } else { -
1616 -
1617 outgoingDataBuffer->chop(bytesToBuffer - bytesBuffered); -
1618 }
-
1619 } -
1620}
-
1621 -
1622 -
1623void QNetworkReplyHttpImplPrivate::_q_networkSessionConnected() -
1624{ -
1625 QNetworkReplyHttpImpl * const q = q_func(); -
1626 -
1627 if (!manager)
-
1628 return;
-
1629 -
1630 QSharedPointer<QNetworkSession> session = managerPrivate->getNetworkSession(); -
1631 if (!session)
-
1632 return;
-
1633 -
1634 if (session->state() != QNetworkSession::Connected)
-
1635 return;
-
1636 -
1637 switch (state) { -
1638 case QNetworkReplyImplPrivate::Buffering: -
1639 case QNetworkReplyImplPrivate::Working: -
1640 case QNetworkReplyImplPrivate::Reconnecting: -
1641 -
1642 migrateBackend(); -
1643 break;
-
1644 case QNetworkReplyImplPrivate::WaitingForSession: -
1645 -
1646 QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); -
1647 break;
-
1648 default: -
1649 ; -
1650 }
-
1651}
-
1652 -
1653void QNetworkReplyHttpImplPrivate::_q_networkSessionFailed() -
1654{ -
1655 -
1656 if (state == WaitingForSession || state == Working) {
-
1657 state = Working; -
1658 QSharedPointer<QNetworkSession> session(manager->d_func()->getNetworkSession()); -
1659 QString errorStr; -
1660 if (session)
-
1661 errorStr = session->errorString();
-
1662 else -
1663 errorStr = QCoreApplication::translate("QNetworkReply", "Network session error.");
-
1664 error(QNetworkReplyImpl::NetworkSessionFailedError, errorStr); -
1665 finished(); -
1666 }
-
1667}
-
1668 -
1669void QNetworkReplyHttpImplPrivate::_q_networkSessionUsagePoliciesChanged(QNetworkSession::UsagePolicies newPolicies) -
1670{ -
1671 if (request.attribute(QNetworkRequest::BackgroundRequestAttribute).toBool()) {
-
1672 if (newPolicies & QNetworkSession::NoBackgroundTrafficPolicy) {
-
1673 -
1674 if (state == WaitingForSession || state == Working) {
-
1675 state = Working; -
1676 error(QNetworkReply::BackgroundRequestNotAllowedError, -
1677 QCoreApplication::translate("QNetworkReply", "Background request not allowed.")); -
1678 finished(); -
1679 }
-
1680 -
1681 }
-
1682 }
-
1683 -
1684}
-
1685 -
1686 -
1687 -
1688 -
1689 -
1690void QNetworkReplyHttpImplPrivate::emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal) -
1691{ -
1692 QNetworkReplyHttpImpl * const q = q_func(); -
1693 if (isFinished)
-
1694 return;
-
1695 -
1696 -
1697 if (uploadProgressSignalChoke.isValid()) {
-
1698 if (bytesSent != bytesTotal && uploadProgressSignalChoke.elapsed() < progressSignalInterval) {
-
1699 return;
-
1700 } -
1701 uploadProgressSignalChoke.restart(); -
1702 } else {
-
1703 uploadProgressSignalChoke.start(); -
1704 }
-
1705 -
1706 q->uploadProgress(bytesSent, bytesTotal); -
1707}
-
1708 -
1709QNonContiguousByteDevice* QNetworkReplyHttpImplPrivate::createUploadByteDevice() -
1710{ -
1711 QNetworkReplyHttpImpl * const q = q_func(); -
1712 -
1713 if (outgoingDataBuffer)
-
1714 uploadByteDevice = QSharedPointer<QNonContiguousByteDevice>(QNonContiguousByteDeviceFactory::create(outgoingDataBuffer));
-
1715 else if (outgoingData) {
-
1716 uploadByteDevice = QSharedPointer<QNonContiguousByteDevice>(QNonContiguousByteDeviceFactory::create(outgoingData)); -
1717 } else {
-
1718 return 0;
-
1719 } -
1720 -
1721 bool bufferDisallowed = -
1722 request.attribute(QNetworkRequest::DoNotBufferUploadDataAttribute, -
1723 QVariant(false)) == QVariant(true); -
1724 if (bufferDisallowed)
-
1725 uploadByteDevice->disableReset();
-
1726 -
1727 -
1728 if (!synchronous)
-
1729 QObject::connect(uploadByteDevice.data(), "2""readProgress(qint64,qint64)", -
1730 q, "1""emitReplyUploadProgress(qint64,qint64)");
-
1731 -
1732 return uploadByteDevice.data();
-
1733} -
1734 -
1735void QNetworkReplyHttpImplPrivate::_q_finished() -
1736{ -
1737 -
1738 finished(); -
1739}
-
1740 -
1741void QNetworkReplyHttpImplPrivate::finished() -
1742{ -
1743 QNetworkReplyHttpImpl * const q = q_func(); -
1744 -
1745 if (state == Finished || state == Aborted || state == WaitingForSession)
-
1746 return;
-
1747 -
1748 QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); -
1749 if (preMigrationDownloaded != static_cast<long long>(-1LL))
-
1750 totalSize = totalSize.toLongLong() + preMigrationDownloaded;
-
1751 -
1752 if (manager) {
-
1753 -
1754 QSharedPointer<QNetworkSession> session = managerPrivate->getNetworkSession(); -
1755 if (session && session->state() == QNetworkSession::Roaming &&
-
1756 state == Working && errorCode != QNetworkReply::OperationCanceledError) {
-
1757 -
1758 if (!totalSize.isNull()) {
-
1759 if (bytesDownloaded != totalSize) {
-
1760 if (migrateBackend()) {
-
1761 -
1762 if (state == Reconnecting || state == WaitingForSession) {
-
1763 return;
-
1764 } -
1765 } else {
-
1766 error(QNetworkReply::TemporaryNetworkFailureError, -
1767 QNetworkReply::tr("Temporary network failure.")); -
1768 }
-
1769 } -
1770 }
-
1771 }
-
1772 -
1773 }
-
1774 -
1775 state = Finished; -
1776 q->setFinished(true); -
1777 -
1778 if (totalSize.isNull() || totalSize == -1) {
-
1779 q->downloadProgress(bytesDownloaded, bytesDownloaded); -
1780 } else {
-
1781 q->downloadProgress(bytesDownloaded, totalSize.toLongLong()); -
1782 }
-
1783 -
1784 if (bytesUploaded == -1 && (outgoingData || outgoingDataBuffer))
-
1785 q->uploadProgress(0, 0);
-
1786 -
1787 -
1788 if (totalSize.isNull() || totalSize == -1 || bytesDownloaded == totalSize)
-
1789 completeCacheSave();
-
1790 -
1791 q->readChannelFinished(); -
1792 q->finished(); -
1793}
-
1794 -
1795void QNetworkReplyHttpImplPrivate::_q_error(QNetworkReplyImpl::NetworkError code, const QString &errorMessage) -
1796{ -
1797 this->error(code, errorMessage); -
1798}
-
1799 -
1800 -
1801void QNetworkReplyHttpImplPrivate::error(QNetworkReplyImpl::NetworkError code, const QString &errorMessage) -
1802{ -
1803 QNetworkReplyHttpImpl * const q = q_func(); -
1804 -
1805 if (errorCode != QNetworkReply::NoError) {
-
1806 QMessageLogger("access/qnetworkreplyhttpimpl.cpp", 1916, __PRETTY_FUNCTION__).warning("QNetworkReplyImplPrivate::error: Internal problem, this method must only be called once."); -
1807 return;
-
1808 } -
1809 -
1810 errorCode = code; -
1811 q->setErrorString(errorMessage); -
1812 -
1813 -
1814 -
1815 -
1816 q->error(code); -
1817}
-
1818 -
1819void QNetworkReplyHttpImplPrivate::metaDataChanged() -
1820{ -
1821 -
1822 -
1823 QNetworkReplyHttpImpl * const q = q_func(); -
1824 -
1825 -
1826 if (cookedHeaders.contains(QNetworkRequest::SetCookieHeader) && manager
-
1827 && (static_cast<QNetworkRequest::LoadControl> -
1828 (request.attribute(QNetworkRequest::CookieSaveControlAttribute, -
1829 QNetworkRequest::Automatic).toInt()) == QNetworkRequest::Automatic)) {
-
1830 QList<QNetworkCookie> cookies = -
1831 qvariant_cast<QList<QNetworkCookie> >(cookedHeaders.value(QNetworkRequest::SetCookieHeader)); -
1832 QNetworkCookieJar *jar = manager->cookieJar(); -
1833 if (jar)
-
1834 jar->setCookiesFromUrl(cookies, url);
-
1835 }
-
1836 q->metaDataChanged(); -
1837}
-
1838 -
1839 -
1840 -
1841 -
1842 -
1843bool QNetworkReplyHttpImplPrivate::migrateBackend() -
1844{ -
1845 QNetworkReplyHttpImpl * const q = q_func(); -
1846 -
1847 -
1848 if (state == Finished || state == Aborted)
-
1849 return true;
-
1850 -
1851 -
1852 if (!canResume())
-
1853 return false;
-
1854 -
1855 -
1856 if (outgoingData)
-
1857 return false;
-
1858 -
1859 -
1860 if (cacheLoadDevice)
-
1861 return true;
-
1862 -
1863 state = Reconnecting; -
1864 -
1865 cookedHeaders.clear(); -
1866 rawHeaders.clear(); -
1867 -
1868 preMigrationDownloaded = bytesDownloaded; -
1869 -
1870 setResumeOffset(bytesDownloaded); -
1871 -
1872 q->abortHttpRequest(); -
1873 -
1874 QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); -
1875 -
1876 return true;
-
1877} -
1878 -
1879 -
1880void QNetworkReplyHttpImplPrivate::createCache() -
1881{ -
1882 -
1883 if (!managerPrivate->networkCache
-
1884 || !request.attribute(QNetworkRequest::CacheSaveControlAttribute, true).toBool())
-
1885 return;
-
1886 cacheEnabled = true; -
1887}
-
1888 -
1889bool QNetworkReplyHttpImplPrivate::isCachingEnabled() const -
1890{ -
1891 return (cacheEnabled && managerPrivate->networkCache != 0);
-
1892} -
1893 -
1894void QNetworkReplyHttpImplPrivate::setCachingEnabled(bool enable) -
1895{ -
1896 if (!enable && !cacheEnabled)
-
1897 return;
-
1898 if (enable && cacheEnabled)
-
1899 return;
-
1900 -
1901 if (enable) {
-
1902 if (bytesDownloaded) {
-
1903 QMessageLogger("access/qnetworkreplyhttpimpl.cpp", 2013, __PRETTY_FUNCTION__).debug() << "setCachingEnabled: " << bytesDownloaded << " bytesDownloaded"; -
1904 -
1905 QMessageLogger("access/qnetworkreplyhttpimpl.cpp", 2015, __PRETTY_FUNCTION__).critical("QNetworkReplyImpl: backend error: caching was enabled after some bytes had been written"); -
1906 return;
-
1907 } -
1908 -
1909 createCache(); -
1910 } else {
-
1911 -
1912 -
1913 QMessageLogger("access/qnetworkreplyhttpimpl.cpp", 2023, __PRETTY_FUNCTION__).debug("QNetworkReplyImpl: setCachingEnabled(true) called after setCachingEnabled(false)"); -
1914 managerPrivate->networkCache->remove(url); -
1915 cacheSaveDevice = 0; -
1916 cacheEnabled = false; -
1917 }
-
1918} -
1919 -
1920bool QNetworkReplyHttpImplPrivate::isCachingAllowed() const -
1921{ -
1922 return operation == QNetworkAccessManager::GetOperation || operation == QNetworkAccessManager::HeadOperation;
-
1923} -
1924 -
1925void QNetworkReplyHttpImplPrivate::completeCacheSave() -
1926{ -
1927 if (cacheEnabled && errorCode != QNetworkReplyImpl::NoError) {
-
1928 managerPrivate->networkCache->remove(url); -
1929 } else if (cacheEnabled && cacheSaveDevice) {
-
1930 managerPrivate->networkCache->insert(cacheSaveDevice); -
1931 }
-
1932 cacheSaveDevice = 0; -
1933 cacheEnabled = false; -
1934}
-
1935 -
1936 -
1937 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial