Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: take watermark into account when caching #421

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/SipiCache.cpp
Original file line number Diff line number Diff line change
@@ -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>
19 changes: 14 additions & 5 deletions src/SipiHttpServer.cpp
Original file line number Diff line number Diff line change
@@ -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;

@@ -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);
}
@@ -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;
3 changes: 2 additions & 1 deletion src/SipiHttpServer.hpp
Original file line number Diff line number Diff line change
@@ -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; }