Introduce `get_requested_format` helper

This commit is contained in:
Matthieu Gautier 2022-05-11 12:03:43 +02:00
parent 5d6b0ea96a
commit e51a5b9ebc
3 changed files with 7 additions and 1 deletions

View File

@ -777,7 +777,7 @@ std::unique_ptr<Response> InternalServer::handle_search(const RequestContext& re
renderer.setProtocolPrefix(m_root + "/");
renderer.setSearchProtocolPrefix(m_root + "/search");
renderer.setPageLength(pageLength);
if (request.get_optional_param<std::string>("format", "") == "xml") {
if (request.get_requested_format() == "xml") {
return ContentResponse::build(*this, renderer.getXml(), "application/rss+xml; charset=utf-8",
/*isHomePage =*/false,
/*raw =*/true);

View File

@ -202,4 +202,9 @@ std::string RequestContext::get_user_language() const
return "en";
}
std::string RequestContext::get_requested_format() const
{
return get_optional_param<std::string>("format", "html");
}
}

View File

@ -118,6 +118,7 @@ class RequestContext {
bool can_compress() const { return acceptEncodingGzip; }
std::string get_user_language() const;
std::string get_requested_format() const;
private: // data
std::string full_url;