mirror of https://github.com/kiwix/libkiwix.git
Make the response responsible to detect if we must introduce taskbar.
The response detect if taskbar must be added depending of the mimetype. Now, `set_taskbar` can be call unconditionally (no need to check for the mimetype) And we don't need to call set_taskbar if we have no information to set.
This commit is contained in:
parent
c14c148af7
commit
87b5adcaf4
|
@ -477,7 +477,6 @@ Response InternalServer::build_homepage(const RequestContext& request)
|
|||
response.set_template(RESOURCE::templates::index_html, homepage_data());
|
||||
response.set_mimeType("text/html; charset=utf-8");
|
||||
response.set_compress(true);
|
||||
response.set_taskbar("", "");
|
||||
return response;
|
||||
}
|
||||
|
||||
|
@ -795,7 +794,6 @@ Response InternalServer::handle_captured_external(const RequestContext& request)
|
|||
response.set_template(RESOURCE::templates::captured_external_html, data);
|
||||
response.set_mimeType("text/html; charset=utf-8");
|
||||
response.set_compress(true);
|
||||
response.set_taskbar("", "");
|
||||
return response;
|
||||
}
|
||||
|
||||
|
@ -957,14 +955,13 @@ Response InternalServer::handle_content(const RequestContext& request)
|
|||
auto response = get_default_response();
|
||||
|
||||
response.set_entry(entry, request);
|
||||
response.set_taskbar(bookName, reader->getTitle());
|
||||
|
||||
if (m_verbose.load()) {
|
||||
printf("Found %s\n", entry.getPath().c_str());
|
||||
printf("mimeType: %s\n", response.get_mimeType().c_str());
|
||||
}
|
||||
|
||||
if ( startsWith(response.get_mimeType(), "text/html") )
|
||||
response.set_taskbar(bookName, reader->getTitle());
|
||||
|
||||
return response;
|
||||
}
|
||||
|
|
|
@ -51,8 +51,8 @@ Response::Response(const std::string& root, bool verbose, bool withTaskbar, bool
|
|||
m_withTaskbar(withTaskbar),
|
||||
m_withLibraryButton(withLibraryButton),
|
||||
m_blockExternalLinks(blockExternalLinks),
|
||||
m_addTaskbar(false),
|
||||
m_bookName("")
|
||||
m_bookName(""),
|
||||
m_bookTitle("")
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -127,9 +127,6 @@ std::string render_template(const std::string& template_str, kainjow::mustache::
|
|||
|
||||
void Response::introduce_taskbar()
|
||||
{
|
||||
if ( !m_withTaskbar || !contentDecorationAllowed() )
|
||||
// Taskbar either globally disabled or not allowed for this type
|
||||
return;
|
||||
kainjow::mustache::data data;
|
||||
data.set("root", m_root);
|
||||
data.set("content", m_bookName);
|
||||
|
@ -152,8 +149,6 @@ void Response::introduce_taskbar()
|
|||
|
||||
void Response::inject_externallinks_blocker()
|
||||
{
|
||||
if ( !contentDecorationAllowed() )
|
||||
return;
|
||||
kainjow::mustache::data data;
|
||||
data.set("root", m_root);
|
||||
auto script_tag = render_template(RESOURCE::templates::external_blocker_part_html, data);
|
||||
|
@ -174,7 +169,8 @@ Response::can_compress(const RequestContext& request) const
|
|||
bool
|
||||
Response::contentDecorationAllowed() const
|
||||
{
|
||||
return m_mimeType.find(";raw=true") == std::string::npos;
|
||||
return (startsWith(m_mimeType, "text/html")
|
||||
&& m_mimeType.find(";raw=true") == std::string::npos);
|
||||
}
|
||||
|
||||
MHD_Response*
|
||||
|
@ -194,11 +190,13 @@ Response::create_error_response(const RequestContext& request) const
|
|||
MHD_Response*
|
||||
Response::create_raw_content_mhd_response(const RequestContext& request)
|
||||
{
|
||||
if (m_addTaskbar) {
|
||||
introduce_taskbar();
|
||||
}
|
||||
if ( m_blockExternalLinks && startsWith(m_mimeType, "text/html") ) {
|
||||
inject_externallinks_blocker();
|
||||
if (contentDecorationAllowed()) {
|
||||
if (m_withTaskbar) {
|
||||
introduce_taskbar();
|
||||
}
|
||||
if (m_blockExternalLinks) {
|
||||
inject_externallinks_blocker();
|
||||
}
|
||||
}
|
||||
|
||||
bool shouldCompress = m_compress && can_compress(request);
|
||||
|
@ -360,7 +358,6 @@ void Response::set_entry(const Entry& entry, const RequestContext& request) {
|
|||
|
||||
void Response::set_taskbar(const std::string& bookName, const std::string& bookTitle)
|
||||
{
|
||||
m_addTaskbar = true;
|
||||
m_bookName = bookName;
|
||||
m_bookTitle = bookTitle;
|
||||
}
|
||||
|
|
|
@ -92,7 +92,6 @@ class Response {
|
|||
bool m_withLibraryButton;
|
||||
bool m_blockExternalLinks;
|
||||
bool m_compress;
|
||||
bool m_addTaskbar;
|
||||
std::string m_bookName;
|
||||
std::string m_bookTitle;
|
||||
ByteRange m_byteRange;
|
||||
|
|
Loading…
Reference in New Issue