From ec2e10b40eac7815bb92c2a5611ad5a12f27d196 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Thu, 24 Mar 2022 20:04:01 +0400 Subject: [PATCH] Moved taskbarInfo into ContentResponseBlueprint --- src/server/response.cpp | 16 +++++----------- src/server/response.h | 32 ++++++++++++++++---------------- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/server/response.cpp b/src/server/response.cpp index 9c049900c..50a66c344 100644 --- a/src/server/response.cpp +++ b/src/server/response.cpp @@ -115,7 +115,9 @@ std::unique_ptr ContentResponseBlueprint::generateResponseObjec { auto r = ContentResponse::build(m_server, m_template, m_data, m_mimeType); r->set_code(m_httpStatusCode); - return r; + return m_taskbarInfo + ? withTaskbarInfo(m_taskbarInfo->bookName, m_taskbarInfo->archive, std::move(r)) + : std::move(r); } HTTP404HtmlResponse::HTTP404HtmlResponse(const InternalServer& server, @@ -143,20 +145,12 @@ HTTP404HtmlResponse& HTTP404HtmlResponse::operator+(const std::string& msg) return *this; } -HTTP404HtmlResponse& HTTP404HtmlResponse::operator+(const TaskbarInfo& taskbarInfo) +ContentResponseBlueprint& ContentResponseBlueprint::operator+(const TaskbarInfo& taskbarInfo) { - this->taskbarInfo.reset(new TaskbarInfo(taskbarInfo)); + this->m_taskbarInfo.reset(new TaskbarInfo(taskbarInfo)); return *this; } -std::unique_ptr HTTP404HtmlResponse::generateResponseObject() const -{ - auto r = ContentResponseBlueprint::generateResponseObject(); - return taskbarInfo - ? withTaskbarInfo(taskbarInfo->bookName, taskbarInfo->archive, std::move(r)) - : std::move(r); -} - std::unique_ptr Response::build_416(const InternalServer& server, size_t resourceLength) { auto response = Response::build(server); diff --git a/src/server/response.h b/src/server/response.h index c0654da1a..b10524bc8 100644 --- a/src/server/response.h +++ b/src/server/response.h @@ -129,6 +129,17 @@ class ContentResponse : public Response { std::string m_bookTitle; }; +struct TaskbarInfo +{ + const std::string bookName; + const zim::Archive* const archive; + + TaskbarInfo(const std::string& bookName, const zim::Archive* a = nullptr) + : bookName(bookName) + , archive(a) + {} +}; + std::unique_ptr withTaskbarInfo(const std::string& bookName, const zim::Archive* archive, std::unique_ptr r); @@ -166,6 +177,9 @@ public: // functions return operator std::unique_ptr(); } + + ContentResponseBlueprint& operator+(const TaskbarInfo& taskbarInfo); + protected: // functions virtual std::unique_ptr generateResponseObject() const; @@ -176,35 +190,21 @@ public: //data const std::string m_mimeType; const std::string m_template; kainjow::mustache::data m_data; + std::unique_ptr m_taskbarInfo; }; class UrlNotFoundMsg {}; extern const UrlNotFoundMsg urlNotFoundMsg; -struct TaskbarInfo -{ - const std::string bookName; - const zim::Archive* const archive; - - TaskbarInfo(const std::string& bookName, const zim::Archive* a = nullptr) - : bookName(bookName) - , archive(a) - {} -}; - struct HTTP404HtmlResponse : ContentResponseBlueprint { HTTP404HtmlResponse(const InternalServer& server, const RequestContext& request); + using ContentResponseBlueprint::operator+; HTTP404HtmlResponse& operator+(UrlNotFoundMsg /*unused*/); HTTP404HtmlResponse& operator+(const std::string& errorDetails); - HTTP404HtmlResponse& operator+(const TaskbarInfo& taskbarInfo); - - std::unique_ptr generateResponseObject() const override; - - std::unique_ptr taskbarInfo; }; class ItemResponse : public Response {