From 6a651e04e53bad79516f6800ed80f694cf23817a Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Wed, 29 Nov 2023 18:19:33 +0400 Subject: [PATCH] 1st step in removing root from ContentResponse It turned out that ContentResponse::m_root is no longer used. At this point, the root parameter is dropped only from the 3-ary variant of ContentResponse::build(), so that its all call sites are automatically discovered by the compiler (and updated manually). Including the other (4-ary) variant of ContentResponse::build() in this change might result in the semantic change of expressions like `ContentResponse::build(x, y, z)` and failure to update them. --- src/server/internalServer.cpp | 15 +++------------ src/server/internalServer_catalog.cpp | 6 ------ src/server/response.cpp | 9 +++------ src/server/response.h | 3 --- 4 files changed, 6 insertions(+), 27 deletions(-) diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index 4fb138e82..4f4b986c6 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -739,7 +739,7 @@ std::unique_ptr InternalServer::handle_suggest(const RequestContext& r results.addFTSearchSuggestion(request.get_user_language(), queryString); } - return ContentResponse::build(m_root, results.getJSON(), "application/json; charset=utf-8"); + return ContentResponse::build(results.getJSON(), "application/json; charset=utf-8"); } std::unique_ptr InternalServer::handle_viewer_settings(const RequestContext& request) @@ -815,11 +815,7 @@ std::unique_ptr InternalServer::handle_no_js(const RequestContext& req return UrlNotFoundResponse(m_root, request); } - return ContentResponse::build( - m_root, - content, - "text/html; charset=utf-8" - ); + return ContentResponse::build(content, "text/html; charset=utf-8"); } namespace @@ -857,7 +853,6 @@ std::unique_ptr InternalServer::handle_skin(const RequestContext& requ try { const auto accessType = staticResourceAccessType(request, resourceCacheId); auto response = ContentResponse::build( - m_root, getResource(resourceName), getMimeTypeForFile(resourceName)); response->set_kind(accessType); @@ -959,13 +954,11 @@ std::unique_ptr InternalServer::handle_search_request(const RequestCon renderer.setPageLength(pageLength); if (request.get_requested_format() == "xml") { return ContentResponse::build( - m_root, renderer.getXml(*mp_nameMapper, mp_library.get()), "application/rss+xml; charset=utf-8" ); } auto response = ContentResponse::build( - m_root, renderer.getHtml(*mp_nameMapper, mp_library.get()), "text/html; charset=utf-8" ); @@ -1267,9 +1260,7 @@ std::unique_ptr InternalServer::handle_locally_customized_resource(con return Response::build_416(resourceData.size()); } - return ContentResponse::build(m_root, - resourceData, - crd.mimeType); + return ContentResponse::build(resourceData, crd.mimeType); } } diff --git a/src/server/internalServer_catalog.cpp b/src/server/internalServer_catalog.cpp index b44e86b46..edb1b327c 100644 --- a/src/server/internalServer_catalog.cpp +++ b/src/server/internalServer_catalog.cpp @@ -93,7 +93,6 @@ std::unique_ptr InternalServer::handle_catalog(const RequestContext& r } auto response = ContentResponse::build( - m_root, opdsDumper.dumpOPDSFeed(bookIdsToDump, request.get_query()), opdsMimeType[OPDS_ACQUISITION_FEED]); return std::move(response); @@ -166,7 +165,6 @@ std::unique_ptr InternalServer::handle_catalog_v2_entries(const Reques const auto bookIds = search_catalog(request, opdsDumper); const auto opdsFeed = opdsDumper.dumpOPDSFeedV2(bookIds, request.get_query(), partial); return ContentResponse::build( - m_root, opdsFeed, opdsMimeType[OPDS_ACQUISITION_FEED] ); @@ -185,7 +183,6 @@ std::unique_ptr InternalServer::handle_catalog_v2_complete_entry(const opdsDumper.setLibraryId(getLibraryId()); const auto opdsFeed = opdsDumper.dumpOPDSCompleteEntry(entryId); return ContentResponse::build( - m_root, opdsFeed, opdsMimeType[OPDS_ENTRY] ); @@ -197,7 +194,6 @@ std::unique_ptr InternalServer::handle_catalog_v2_categories(const Req opdsDumper.setRootLocation(m_root); opdsDumper.setLibraryId(getLibraryId()); return ContentResponse::build( - m_root, opdsDumper.categoriesOPDSFeed(), opdsMimeType[OPDS_NAVIGATION_FEED] ); @@ -209,7 +205,6 @@ std::unique_ptr InternalServer::handle_catalog_v2_languages(const Requ opdsDumper.setRootLocation(m_root); opdsDumper.setLibraryId(getLibraryId()); return ContentResponse::build( - m_root, opdsDumper.languagesOPDSFeed(), opdsMimeType[OPDS_NAVIGATION_FEED] ); @@ -223,7 +218,6 @@ std::unique_ptr InternalServer::handle_catalog_v2_illustration(const R auto size = request.get_argument("size"); auto illustration = book.getIllustration(size); return ContentResponse::build( - m_root, illustration->getData(), illustration->mimeType ); diff --git a/src/server/response.cpp b/src/server/response.cpp index 262bff890..04d158652 100644 --- a/src/server/response.cpp +++ b/src/server/response.cpp @@ -386,9 +386,8 @@ MHD_Result Response::send(const RequestContext& request, bool verbose, MHD_Conne return ret; } -ContentResponse::ContentResponse(const std::string& root, const std::string& content, const std::string& mimetype) : +ContentResponse::ContentResponse(const std::string& content, const std::string& mimetype) : Response(), - m_root(root), m_content(content), m_mimeType(mimetype) { @@ -396,12 +395,10 @@ ContentResponse::ContentResponse(const std::string& root, const std::string& con } std::unique_ptr ContentResponse::build( - const std::string& root, const std::string& content, const std::string& mimetype) { return std::unique_ptr(new ContentResponse( - root, content, mimetype)); } @@ -413,7 +410,7 @@ std::unique_ptr ContentResponse::build( const std::string& mimetype) { auto content = render_template(template_str, data); - return ContentResponse::build(root, content, mimetype); + return ContentResponse::build(content, mimetype); } ItemResponse::ItemResponse(const zim::Item& item, const std::string& mimetype, const ByteRange& byterange) : @@ -433,7 +430,7 @@ std::unique_ptr ItemResponse::build(const std::string& root, const Req const bool noRange = byteRange.kind() == ByteRange::RESOLVED_FULL_CONTENT; if (noRange && is_compressible_mime_type(mimetype)) { // Return a contentResponse - auto response = ContentResponse::build(root, item.getData(), mimetype); + auto response = ContentResponse::build(item.getData(), mimetype); response->set_kind(Response::ZIM_CONTENT); response->m_byteRange = byteRange; return std::move(response); diff --git a/src/server/response.h b/src/server/response.h index 428e65392..7c3f2cf3f 100644 --- a/src/server/response.h +++ b/src/server/response.h @@ -89,12 +89,10 @@ class Response { class ContentResponse : public Response { public: ContentResponse( - const std::string& root, const std::string& content, const std::string& mimetype); static std::unique_ptr build( - const std::string& root, const std::string& content, const std::string& mimetype); @@ -111,7 +109,6 @@ class ContentResponse : public Response { private: - std::string m_root; std::string m_content; std::string m_mimeType; };