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