From 545d4091501263747209bcb7a414edb013e5aff0 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Tue, 29 Mar 2022 22:43:22 +0400 Subject: [PATCH] Reused HTTPErrorHtmlResponse in HTTP400HtmlResponse --- src/server/response.cpp | 21 ++++++--------------- src/server/response.h | 7 +++---- static/resources_list.txt | 1 - static/templates/400.html | 15 --------------- 4 files changed, 9 insertions(+), 35 deletions(-) delete mode 100644 static/templates/400.html diff --git a/src/server/response.cpp b/src/server/response.cpp index 49caed531..01b8bf97d 100644 --- a/src/server/response.cpp +++ b/src/server/response.cpp @@ -141,17 +141,15 @@ HTTPErrorHtmlResponse& HTTPErrorHtmlResponse::operator+(const std::string& msg) HTTP400HtmlResponse::HTTP400HtmlResponse(const InternalServer& server, const RequestContext& request) - : ContentResponseBlueprint(&server, - &request, - MHD_HTTP_BAD_REQUEST, - "text/html", - RESOURCE::templates::_400_html) + : HTTPErrorHtmlResponse(server, + request, + MHD_HTTP_BAD_REQUEST, + "Invalid request", + "Invalid request") { - kainjow::mustache::list emptyList; - this->m_data = kainjow::mustache::object{{"details", emptyList}}; } -HTTP400HtmlResponse& HTTP400HtmlResponse::operator+(InvalidUrlMsg /*unused*/) +HTTPErrorHtmlResponse& HTTP400HtmlResponse::operator+(InvalidUrlMsg /*unused*/) { std::string requestUrl = m_request.get_full_url(); const auto query = m_request.get_query(); @@ -162,13 +160,6 @@ HTTP400HtmlResponse& HTTP400HtmlResponse::operator+(InvalidUrlMsg /*unused*/) return *this + msgTmpl.render({"url", requestUrl}); } -HTTP400HtmlResponse& HTTP400HtmlResponse::operator+(const std::string& msg) -{ - m_data["details"].push_back({"p", msg}); - return *this; -} - - ContentResponseBlueprint& ContentResponseBlueprint::operator+(const TaskbarInfo& taskbarInfo) { this->m_taskbarInfo.reset(new TaskbarInfo(taskbarInfo)); diff --git a/src/server/response.h b/src/server/response.h index 245c1396d..f7546f269 100644 --- a/src/server/response.h +++ b/src/server/response.h @@ -208,14 +208,13 @@ class InvalidUrlMsg {}; extern const InvalidUrlMsg invalidUrlMsg; -struct HTTP400HtmlResponse : ContentResponseBlueprint +struct HTTP400HtmlResponse : HTTPErrorHtmlResponse { HTTP400HtmlResponse(const InternalServer& server, const RequestContext& request); - using ContentResponseBlueprint::operator+; - HTTP400HtmlResponse& operator+(InvalidUrlMsg /*unused*/); - HTTP400HtmlResponse& operator+(const std::string& errorDetails); + using HTTPErrorHtmlResponse::operator+; + HTTPErrorHtmlResponse& operator+(InvalidUrlMsg /*unused*/); }; class ItemResponse : public Response { diff --git a/static/resources_list.txt b/static/resources_list.txt index c51f19acd..258553a2a 100644 --- a/static/resources_list.txt +++ b/static/resources_list.txt @@ -36,7 +36,6 @@ skin/search_results.css templates/search_result.html templates/no_search_result.html templates/error.html -templates/400.html templates/500.html templates/index.html templates/suggestion.json diff --git a/static/templates/400.html b/static/templates/400.html deleted file mode 100644 index 5f4ecf42f..000000000 --- a/static/templates/400.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - - Invalid request - - -

Invalid request

-{{#details}} -

- {{{p}}} -

-{{/details}} - -