Skip to content

Commit

Permalink
fix: take watermark into account when caching (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
subotic authored Mar 26, 2024
1 parent 5f3610e commit 18788b2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/SipiCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@

#endif

#include <assert.h>
#include <cassert>
#include <dirent.h>
#include <stdio.h>
#include <sys/stat.h>
#include <syslog.h>
#include <unistd.h>
Expand Down
19 changes: 14 additions & 5 deletions src/SipiHttpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,8 @@ std::pair<std::string, std::string> SipiHttpServer::get_canonical_url(size_t tmp
std::shared_ptr<SipiSize> size,
SipiRotation &rotation,
SipiQualityFormat &quality_format,
int pagenum)
int pagenum,
const std::string& cannonical_watermark)
{
static constexpr int canonical_len = 127;

Expand Down Expand Up @@ -560,17 +561,22 @@ std::pair<std::string, std::string> SipiHttpServer::get_canonical_url(size_t tmp
if (pagenum > 0) fullid += "@" + std::to_string(pagenum);
(void)snprintf(canonical_header,
canonical_header_len,
"<http://%s/%s/%s/%s/%s/%s/default.%s>;rel=\"canonical\"",
"<http://%s/%s/%s/%s/%s/%s/default.%s/%s>;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);
}
Expand Down Expand Up @@ -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
//
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/SipiHttpServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class SipiHttpServer : public shttps::Server
std::shared_ptr<SipiSize> size,
SipiRotation &rotation,
SipiQualityFormat &quality_format,
int pagenum = 0);
int pagenum = 0,
const std::string &canonnical_watermark = "0");


pid_t pid() const { return _pid; }
Expand Down

0 comments on commit 18788b2

Please sign in to comment.