From a67456111098557dcd8223240c25ee6a656f608b Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Wed, 29 Jun 2022 11:53:43 +0400 Subject: [PATCH] Dropped root link injection The only place that the root link is now used is in /skin/index.js, so added it in static/templates/index.html. But it seems that nothing prevents us from from switching from aboslute paths to relative paths in /skin/index.js, which will eliminate the need for the root link altogether. As a result of this change content is never decorated by kiwix serve. --- src/server/response.cpp | 11 ----------- src/server/response.h | 1 - static/templates/index.html | 1 + test/server.cpp | 5 +++-- test/server_search.cpp | 2 +- 5 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/server/response.cpp b/src/server/response.cpp index ddda140a..9bf061df 100644 --- a/src/server/response.cpp +++ b/src/server/response.cpp @@ -321,13 +321,6 @@ void print_response_info(int retCode, MHD_Response* response) } -void ContentResponse::inject_root_link(){ - m_content = prependToFirstOccurence( - m_content, - "", - ""); -} - bool ContentResponse::can_compress(const RequestContext& request) const { @@ -356,10 +349,6 @@ Response::create_mhd_response(const RequestContext& request) MHD_Response* ContentResponse::create_mhd_response(const RequestContext& request) { - if (contentDecorationAllowed()) { - inject_root_link(); - } - const bool isCompressed = can_compress(request) && compress(m_content); MHD_Response* response = MHD_create_response_from_buffer( diff --git a/src/server/response.h b/src/server/response.h index a19079b6..35d53c34 100644 --- a/src/server/response.h +++ b/src/server/response.h @@ -103,7 +103,6 @@ class ContentResponse : public Response { private: MHD_Response* create_mhd_response(const RequestContext& request); - void inject_root_link(); bool can_compress(const RequestContext& request) const; bool contentDecorationAllowed() const; diff --git a/static/templates/index.html b/static/templates/index.html index c7ffaf0d..42bbc6a1 100644 --- a/static/templates/index.html +++ b/static/templates/index.html @@ -3,6 +3,7 @@ + Welcome to Kiwix Server "); EXPECT_EQ("" "Welcome to kiwix library" - "" "" "", zfs.GET("/ROOT/")->body); } @@ -447,7 +446,7 @@ std::string TestContentIn404HtmlResponse::expectedResponse() const )FRAG", R"FRAG( - + )FRAG", R"FRAG( @@ -1028,11 +1027,13 @@ TEST_F(ServerTest, RawEntry) EXPECT_EQ(200, p->status); EXPECT_EQ(std::string(p->body), std::string(entry.getItem(true).getData())); + /* Now normal content is not decorated in any way, either // ... but the "normal" content is not p = zfs1_->GET("/ROOT/content/zimfile/A/Ray_Charles"); EXPECT_EQ(200, p->status); EXPECT_NE(std::string(p->body), std::string(entry.getItem(true).getData())); EXPECT_TRUE(p->body.find("") != std::string::npos); + */ } TEST_F(ServerTest, HeadMethodIsSupported) diff --git a/test/server_search.cpp b/test/server_search.cpp index 5e540ce9..435763d7 100644 --- a/test/server_search.cpp +++ b/test/server_search.cpp @@ -112,7 +112,7 @@ std::string makeSearchResultsHtml(const std::string& pattern, Search: %PATTERN% - +
%HEADER%