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.
This commit is contained in:
Veloman Yunkan 2023-11-29 18:19:33 +04:00
parent 22ea3106c5
commit 6a651e04e5
4 changed files with 6 additions and 27 deletions

View File

@ -739,7 +739,7 @@ std::unique_ptr<Response> 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<Response> InternalServer::handle_viewer_settings(const RequestContext& request)
@ -815,11 +815,7 @@ std::unique_ptr<Response> 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<Response> 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<Response> 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<Response> 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);
}
}

View File

@ -93,7 +93,6 @@ std::unique_ptr<Response> 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<Response> 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<Response> 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<Response> 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<Response> 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<Response> InternalServer::handle_catalog_v2_illustration(const R
auto size = request.get_argument<unsigned int>("size");
auto illustration = book.getIllustration(size);
return ContentResponse::build(
m_root,
illustration->getData(),
illustration->mimeType
);

View File

@ -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> ContentResponse::build(
const std::string& root,
const std::string& content,
const std::string& mimetype)
{
return std::unique_ptr<ContentResponse>(new ContentResponse(
root,
content,
mimetype));
}
@ -413,7 +410,7 @@ std::unique_ptr<ContentResponse> 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<Response> 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);

View File

@ -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<ContentResponse> 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;
};