| 75 | } |
| 76 | |
| 77 | Task::State MetaCacheSink::finalizeCache(QNetworkReply& reply) |
| 78 | { |
| 79 | QFileInfo output_file_info(m_filename); |
| 80 | |
| 81 | if (m_wroteAnyData) { |
| 82 | m_entry->setMD5Sum(m_md5Node->hash().toHex().constData()); |
| 83 | } |
| 84 | |
| 85 | m_entry->setETag(reply.rawHeader("ETag").constData()); |
| 86 | |
| 87 | if (reply.hasRawHeader("Last-Modified")) { |
| 88 | m_entry->setRemoteChangedTimestamp(reply.rawHeader("Last-Modified").constData()); |
| 89 | } |
| 90 | |
| 91 | m_entry->setLocalChangedTimestamp(output_file_info.lastModified().toUTC().toMSecsSinceEpoch()); |
| 92 | |
| 93 | { // Cache lifetime |
| 94 | if (m_is_eternal) { |
| 95 | qCDebug(taskMetaCacheLogC) << "Adding eternal cache entry:" << m_entry->getFullPath(); |
| 96 | m_entry->makeEternal(true); |
| 97 | } else if (reply.hasRawHeader("Cache-Control")) { |
| 98 | auto cache_control_header = reply.rawHeader("Cache-Control"); |
| 99 | qCDebug(taskMetaCacheLogC) << "Parsing 'Cache-Control' header with" << cache_control_header; |
| 100 | |
| 101 | QRegularExpression max_age_expr("max-age=([0-9]+)"); |
| 102 | qint64 max_age = max_age_expr.match(cache_control_header).captured(1).toLongLong(); |
| 103 | m_entry->setMaximumAge(max_age); |
| 104 | |
| 105 | } else if (reply.hasRawHeader("Expires")) { |
| 106 | auto expires_header = reply.rawHeader("Expires"); |
| 107 | qCDebug(taskMetaCacheLogC) << "Parsing 'Expires' header with" << expires_header; |
| 108 | |
| 109 | qint64 max_age = QDateTime::fromString(expires_header).toSecsSinceEpoch() - QDateTime::currentSecsSinceEpoch(); |
| 110 | m_entry->setMaximumAge(max_age); |
| 111 | } else { |
| 112 | m_entry->setMaximumAge(MAX_TIME_TO_EXPIRE); |
| 113 | } |
| 114 | |
| 115 | if (reply.hasRawHeader("Age")) { |
| 116 | auto age_header = reply.rawHeader("Age"); |
| 117 | qCDebug(taskMetaCacheLogC) << "Parsing 'Age' header with" << age_header; |
| 118 | |
| 119 | qint64 current_age = age_header.toLongLong(); |
| 120 | m_entry->setCurrentAge(current_age); |
| 121 | } else { |
| 122 | m_entry->setCurrentAge(0); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | m_entry->setStale(false); |
| 127 | APPLICATION->metacache()->updateEntry(m_entry); |
| 128 | |
| 129 | return Task::State::Succeeded; |
| 130 | } |
| 131 | |
| 132 | bool MetaCacheSink::hasLocalData() |
| 133 | { |
nothing calls this directly
no test coverage detected