From 85f6781d8145133d610b34518bbdf19a992b0fde Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Tue, 16 May 2017 22:58:09 +0100 Subject: [PATCH] Fix tawashi sending back an html response even for redirects. --- src/tawashi_implem/response.cpp | 29 ++++++++++++-------- src/tawashi_implem/submit_paste_response.hpp | 3 +- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/tawashi_implem/response.cpp b/src/tawashi_implem/response.cpp index e929860..d547cf1 100644 --- a/src/tawashi_implem/response.cpp +++ b/src/tawashi_implem/response.cpp @@ -177,6 +177,7 @@ namespace tawashi { this->on_mustache_prepare(mustache_context); m_header_sent = true; + bool render_page = true; switch (m_resp_type) { case ContentType: SPDLOG_TRACE(statuslog, "Response is a Content-type (data)"); @@ -185,21 +186,25 @@ namespace tawashi { case Location: SPDLOG_TRACE(statuslog, "Response is a Location (redirect)"); *m_stream_out << "Location: " << m_resp_value << "\n\n"; + render_page = false; break; } - SPDLOG_TRACE(statuslog, "Rendering in mustache"); - *m_stream_out << mstch::render( - on_mustache_retrieve(), - mustache_context, - std::bind( - &load_whole_file, - std::cref(m_website_root), - ".mustache", - std::placeholders::_1, - false - ) - ); + if (render_page) { + SPDLOG_TRACE(statuslog, "Rendering in mustache"); + *m_stream_out << mstch::render( + on_mustache_retrieve(), + mustache_context, + std::bind( + &load_whole_file, + std::cref(m_website_root), + ".mustache", + std::placeholders::_1, + false + ) + ); + } + SPDLOG_TRACE(statuslog, "Flushing output"); m_stream_out->flush(); } diff --git a/src/tawashi_implem/submit_paste_response.hpp b/src/tawashi_implem/submit_paste_response.hpp index 253ecc7..bcfb4f1 100644 --- a/src/tawashi_implem/submit_paste_response.hpp +++ b/src/tawashi_implem/submit_paste_response.hpp @@ -22,6 +22,7 @@ #include #include #include +#include namespace tawashi { class SubmitPasteResponse : public Response { @@ -33,7 +34,7 @@ namespace tawashi { ); protected: - virtual boost::string_ref page_basename() const override { return boost::string_ref("paste"); } + virtual boost::string_ref page_basename() const override { assert(false); return boost::string_ref(""); } private: virtual void on_process() override;