From 69ebab70937dbcae6d55502cef7c0cfc6a4461c4 Mon Sep 17 00:00:00 2001 From: Ivan Subotic <400790+subotic@users.noreply.github.com> Date: Tue, 26 Mar 2024 22:26:07 +0100 Subject: [PATCH] fix: take watermark into account when caching --- src/SipiCache.cpp | 3 +-- src/SipiHttpServer.cpp | 19 ++++++++++++++----- src/SipiHttpServer.hpp | 3 ++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/SipiCache.cpp b/src/SipiCache.cpp index ed73a34f..115fb7a1 100644 --- a/src/SipiCache.cpp +++ b/src/SipiCache.cpp @@ -20,9 +20,8 @@ #endif -#include +#include #include -#include #include #include #include diff --git a/src/SipiHttpServer.cpp b/src/SipiHttpServer.cpp index 3d3149cf..086536fa 100644 --- a/src/SipiHttpServer.cpp +++ b/src/SipiHttpServer.cpp @@ -448,7 +448,8 @@ std::pair SipiHttpServer::get_canonical_url(size_t tmp std::shared_ptr size, SipiRotation &rotation, SipiQualityFormat &quality_format, - int pagenum) + int pagenum, + const std::string& cannonical_watermark) { static constexpr int canonical_len = 127; @@ -560,17 +561,22 @@ std::pair SipiHttpServer::get_canonical_url(size_t tmp if (pagenum > 0) fullid += "@" + std::to_string(pagenum); (void)snprintf(canonical_header, canonical_header_len, - ";rel=\"canonical\"", + ";rel=\"canonical\"", host.c_str(), prefix.c_str(), fullid.c_str(), canonical_region, canonical_size, canonical_rotation, - ext); + ext, + cannonical_watermark.c_str()); + + // Here we are creating the canonical URL. Attention: We have added the watermark to the URL, which is not part of the + // IIIF standard. This is necessary for correct caching, as the watermark is not part of the image, but is added + // by the server. std::string canonical = host + "/" + prefix + "/" + fullid + "/" + std::string(canonical_region) + "/" + std::string(canonical_size) + "/" + std::string(canonical_rotation) + format - + std::string(ext); + + std::string{ext} + "/" + std::string{cannonical_watermark}; return make_pair(std::string(canonical_header), canonical); } @@ -1342,6 +1348,8 @@ static void serve_iiif(Connection &conn_obj, // if restricted size is set and smaller, we use it if (!restricted_size->undefined() && (*size > *restricted_size)) { size = restricted_size; } + std::string cannonical_watermark = watermark.empty() ? "0" : "1"; + //..................................................................... // here we start building the canonical URL // @@ -1356,7 +1364,8 @@ static void serve_iiif(Connection &conn_obj, size, rotation, quality_format, - sid.getPage()); + sid.getPage(), + cannonical_watermark); } catch (Sipi::SipiError &err) { send_error(conn_obj, Connection::BAD_REQUEST, err); return; diff --git a/src/SipiHttpServer.hpp b/src/SipiHttpServer.hpp index e6c138b4..84b92d0e 100644 --- a/src/SipiHttpServer.hpp +++ b/src/SipiHttpServer.hpp @@ -76,7 +76,8 @@ class SipiHttpServer : public shttps::Server std::shared_ptr size, SipiRotation &rotation, SipiQualityFormat &quality_format, - int pagenum = 0); + int pagenum = 0, + const std::string &canonnical_watermark = "0"); pid_t pid() const { return _pid; }