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.
This commit is contained in:
Veloman Yunkan 2022-06-26 14:02:54 +04:00
parent c988511561
commit eb0a45b13e
4 changed files with 28 additions and 10 deletions

View File

@ -823,7 +823,9 @@ std::unique_ptr<Response> 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<Response> 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);
}

View File

@ -103,7 +103,9 @@ std::unique_ptr<Response> 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<Response> 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<Response> 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<Response> 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<Response> InternalServer::handle_catalog_v2_illustration(const R
auto book = mp_library->getBookByIdThreadSafe(bookId);
auto size = request.get_argument<unsigned int>("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;

View File

@ -448,7 +448,7 @@ std::unique_ptr<ContentResponse> 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) :

View File

@ -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<ContentResponse> build(
const InternalServer& server,