Mercurial > hg > orthanc
diff OrthancServer/Sources/ServerContext.cpp @ 5406:aaf7c49a9ddc am-http-compression
tentative to implement smart HTTP compression with detection of transfer syntax
author | Alain Mazy <am@osimis.io> |
---|---|
date | Sat, 04 Nov 2023 13:42:30 +0100 |
parents | 566e8d32bd3a |
children |
line wrap: on
line diff
--- a/OrthancServer/Sources/ServerContext.cpp Tue Oct 17 15:06:11 2023 +0200 +++ b/OrthancServer/Sources/ServerContext.cpp Sat Nov 04 13:42:30 2023 +0100 @@ -898,8 +898,23 @@ } else { + ContentCompression contentCompression = ContentCompression_Unknown; + + // try to avoid compressing a large DICOM file ( > 1MB) that is already compressed (For large files, this could take multiple seconds) + std::string transferSyntaxString; + DicomTransferSyntax transferSyntax; + int64_t revision; + + if (content == FileContentType_Dicom && + attachment.GetUncompressedSize() > 1*1024*1024 && // don't even waste time reading the TransferSyntax from DB for "small" DICOM files + index_.LookupMetadata(transferSyntaxString, revision, resourceId, ResourceType_Instance, MetadataType_Instance_TransferSyntax) && + LookupTransferSyntax(transferSyntax, transferSyntaxString)) + { + contentCompression = (IsCompressedTransferSyntax(transferSyntax) ? ContentCompression_AlreadyCompressed : ContentCompression_NotCompressed); + } + StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); - accessor.AnswerFile(output, attachment, GetFileContentMime(content)); + accessor.AnswerFile(output, attachment, GetFileContentMime(content), contentCompression); } }