Fixed #391: prevent taskbar and blocker at article level

Some HTML articles are meant to be displayed through a viewer. In this case,
we know we don't want the server to inject the taskbar nor the link blocker
because the content is not a user-ready web page but a partial element of it.

Such articles still need to be `text/html` to be parsed properly by browsers.

This changes the way we decide to display the tasbar or not.
Previously, we were adding it to every article with a MIME __starting with__ `text/html`.
Now, we're additionally preventing it on `text/html` MIME if there is a `;raw=true` string inside.

This leaves articles with MIME `text/html;raw=true` (warc2zim convention) outside
of the taskbar target.

For similar reasons, the external-link blocker is set to apply to the same set of articles.
Previously, it was applied to all articles which was an (unoticable) mistake.
This commit is contained in:
renaud gaudin 2020-08-06 14:27:36 +02:00
parent 98a10d2ca1
commit 3f25a3d005
3 changed files with 13 additions and 4 deletions

View File

@ -963,7 +963,7 @@ Response InternalServer::handle_content(const RequestContext& request)
printf("mimeType: %s\n", response.get_mimeType().c_str());
}
if (response.get_mimeType().find("text/html") != string::npos)
if ( startsWith(response.get_mimeType(), "text/html") )
response.set_taskbar(bookName, reader->getTitle());
return response;

View File

@ -127,8 +127,8 @@ std::string render_template(const std::string& template_str, kainjow::mustache::
void Response::introduce_taskbar()
{
if (! m_withTaskbar)
// Taskbar is globally disabled.
if ( !m_withTaskbar || !contentDecorationAllowed() )
// Taskbar either globally disabled or not allowed for this type
return;
kainjow::mustache::data data;
data.set("root", m_root);
@ -152,6 +152,8 @@ 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);
@ -169,6 +171,12 @@ Response::can_compress(const RequestContext& request) const
&& (m_content.size() > KIWIX_MIN_CONTENT_SIZE_TO_DEFLATE);
}
bool
Response::contentDecorationAllowed() const
{
return m_mimeType.find(";raw=true") == std::string::npos;
}
MHD_Response*
Response::create_error_response(const RequestContext& request) const
{
@ -189,7 +197,7 @@ Response::create_raw_content_mhd_response(const RequestContext& request)
if (m_addTaskbar) {
introduce_taskbar();
}
if ( m_blockExternalLinks ) {
if ( m_blockExternalLinks && startsWith(m_mimeType, "text/html") ) {
inject_externallinks_blocker();
}

View File

@ -71,6 +71,7 @@ class Response {
void inject_externallinks_blocker();
bool can_compress(const RequestContext& request) const;
bool contentDecorationAllowed() const;
private: // functions
MHD_Response* create_mhd_response(const RequestContext& request);