1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-26 22:44:36 +00:00

Cache and reuse detected MIME type

This commit is contained in:
Chocobo1 2019-08-14 17:48:40 +08:00
parent 973da6feb8
commit 230949ee3b
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
2 changed files with 6 additions and 6 deletions

View File

@ -368,11 +368,10 @@ void WebApplication::sendFile(const QString &path)
const QDateTime lastModified {QFileInfo(path).lastModified()};
// find translated file in cache
auto it = m_translatedFiles.constFind(path);
if ((it != m_translatedFiles.constEnd()) && (lastModified <= (*it).lastModified)) {
const QString mimeName {QMimeDatabase().mimeTypeForFileNameAndData(path, (*it).data).name()};
print((*it).data, mimeName);
header(Http::HEADER_CACHE_CONTROL, getCachingInterval(mimeName));
const auto it = m_translatedFiles.constFind(path);
if ((it != m_translatedFiles.constEnd()) && (lastModified <= it->lastModified)) {
print(it->data, it->mimeType);
header(Http::HEADER_CACHE_CONTROL, getCachingInterval(it->mimeType));
return;
}
@ -400,7 +399,7 @@ void WebApplication::sendFile(const QString &path)
translateDocument(dataStr);
data = dataStr.toUtf8();
m_translatedFiles[path] = {data, lastModified}; // caching translated file
m_translatedFiles[path] = {data, mimeType.name(), lastModified}; // caching translated file
}
print(data, mimeType.name());

View File

@ -136,6 +136,7 @@ private:
struct TranslatedFile
{
QByteArray data;
QString mimeType;
QDateTime lastModified;
};
QHash<QString, TranslatedFile> m_translatedFiles;