From eb0a45b13eb7a3d28980d023f95702111340dab4 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sun, 26 Jun 2022 14:02:54 +0400 Subject: [PATCH] Undefaulted bool params of ContentResponse::build() This resulted in compiler aided discovery of all call sites where the default values were used. For OPDS/catalog requests now passing true for the `raw` parameter, since XML content isn't supposed to undergo any transformations. --- src/server/internalServer.cpp | 8 ++++++-- src/server/internalServer_catalog_v2.cpp | 24 +++++++++++++++++++----- src/server/response.cpp | 2 +- src/server/response.h | 4 ++-- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index 9ff0dddb0..f249acded 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -823,7 +823,9 @@ std::unique_ptr InternalServer::handle_search(const RequestContext& re /*isHomePage =*/false, /*raw =*/true); } - auto response = ContentResponse::build(*this, renderer.getHtml(), "text/html; charset=utf-8"); + auto response = ContentResponse::build(*this, renderer.getHtml(), "text/html; charset=utf-8", + /*isHomePage =*/false, + /*raw =*/false); // XXX: Now this has to be handled by the iframe-based viewer which // XXX: has to resolve if the book selection resulted in a single book. /* @@ -953,7 +955,9 @@ std::unique_ptr InternalServer::handle_catalog(const RequestContext& r auto response = ContentResponse::build( *this, opdsDumper.dumpOPDSFeed(bookIdsToDump, request.get_query()), - "application/atom+xml; profile=opds-catalog; kind=acquisition; charset=utf-8"); + "application/atom+xml; profile=opds-catalog; kind=acquisition; charset=utf-8", + /*isHomePage*/ false, + /*raw*/ true); return std::move(response); } diff --git a/src/server/internalServer_catalog_v2.cpp b/src/server/internalServer_catalog_v2.cpp index bc7f1adae..f6314855f 100644 --- a/src/server/internalServer_catalog_v2.cpp +++ b/src/server/internalServer_catalog_v2.cpp @@ -103,7 +103,9 @@ std::unique_ptr InternalServer::handle_catalog_v2_entries(const Reques return ContentResponse::build( *this, opdsFeed, - "application/atom+xml;profile=opds-catalog;kind=acquisition" + "application/atom+xml;profile=opds-catalog;kind=acquisition", + /*isHomePage*/ false, + /*raw*/ true ); } @@ -123,7 +125,9 @@ std::unique_ptr InternalServer::handle_catalog_v2_complete_entry(const return ContentResponse::build( *this, opdsFeed, - "application/atom+xml;type=entry;profile=opds-catalog" + "application/atom+xml;type=entry;profile=opds-catalog", + /*isHomePage*/ false, + /*raw*/ true ); } @@ -135,7 +139,9 @@ std::unique_ptr InternalServer::handle_catalog_v2_categories(const Req return ContentResponse::build( *this, opdsDumper.categoriesOPDSFeed(), - "application/atom+xml;profile=opds-catalog;kind=navigation" + "application/atom+xml;profile=opds-catalog;kind=navigation", + /*isHomePage*/ false, + /*raw*/ true ); } @@ -147,7 +153,9 @@ std::unique_ptr InternalServer::handle_catalog_v2_languages(const Requ return ContentResponse::build( *this, opdsDumper.languagesOPDSFeed(), - "application/atom+xml;profile=opds-catalog;kind=navigation" + "application/atom+xml;profile=opds-catalog;kind=navigation", + /*isHomePage*/ false, + /*raw*/ true ); } @@ -158,7 +166,13 @@ std::unique_ptr InternalServer::handle_catalog_v2_illustration(const R auto book = mp_library->getBookByIdThreadSafe(bookId); auto size = request.get_argument("size"); auto illustration = book.getIllustration(size); - return ContentResponse::build(*this, illustration->getData(), illustration->mimeType); + return ContentResponse::build( + *this, + illustration->getData(), + illustration->mimeType, + /*isHomePage*/ false, + /*raw*/ true + ); } catch(...) { return HTTP404Response(*this, request) + urlNotFoundMsg; diff --git a/src/server/response.cpp b/src/server/response.cpp index a38ef9789..d82e9e7be 100644 --- a/src/server/response.cpp +++ b/src/server/response.cpp @@ -448,7 +448,7 @@ std::unique_ptr ContentResponse::build( const std::string& mimetype) { auto content = render_template(template_str, data); - return ContentResponse::build(server, content, mimetype); + return ContentResponse::build(server, content, mimetype, /*isHomePage*/false, /*raw*/false); } ItemResponse::ItemResponse(bool verbose, const zim::Item& item, const std::string& mimetype, const ByteRange& byterange) : diff --git a/src/server/response.h b/src/server/response.h index 657ecc5d7..182210d50 100644 --- a/src/server/response.h +++ b/src/server/response.h @@ -92,8 +92,8 @@ class ContentResponse : public Response { const InternalServer& server, const std::string& content, const std::string& mimetype, - bool isHomePage = false, - bool raw = false); + bool isHomePage, + bool raw); static std::unique_ptr build( const InternalServer& server,