diff --git a/src/tawashi_implem/submit_paste_response.cpp b/src/tawashi_implem/submit_paste_response.cpp index 3df1387..33a11f4 100644 --- a/src/tawashi_implem/submit_paste_response.cpp +++ b/src/tawashi_implem/submit_paste_response.cpp @@ -155,7 +155,15 @@ namespace tawashi { statuslog->info("Pastie token=\"{}\" redirect=\"{}\"", *token, oss.str()); if (not lang.empty()) oss << '?' << lang; - return this->make_redirect(HttpStatusCodes::Code303_SeeOther, oss.str()); + + //TODO: clean up this hack, make a separate class or something + if (cgi_env().path_info().empty()) { + m_redirect_to = oss.str(); + return HttpHeader(); + } + else { + return this->make_redirect(HttpStatusCodes::Code303_SeeOther, oss.str()); + } } else { statuslog->info("Empty pastie token (possibly due to a previous failure)"); @@ -195,4 +203,12 @@ namespace tawashi { return std::make_pair(boost::optional(), make_error_redirect(ErrorReasons::PastieNotSaved)); } + + void SubmitPasteResponse::on_mustache_prepare (mstch::map& parContext) { + parContext["redirect_to_address"] = m_redirect_to; + } + + std::string SubmitPasteResponse::on_mustache_retrieve() { + return "{{base_uri}}/{{redirect_to_address}}\n"; + } } //namespace tawashi diff --git a/src/tawashi_implem/submit_paste_response.hpp b/src/tawashi_implem/submit_paste_response.hpp index 5980c9c..e6c242d 100644 --- a/src/tawashi_implem/submit_paste_response.hpp +++ b/src/tawashi_implem/submit_paste_response.hpp @@ -39,6 +39,12 @@ namespace tawashi { private: typedef std::pair, HttpHeader> StringOrHeader; virtual HttpHeader on_process() override; + virtual void on_mustache_prepare (mstch::map& parContext) override; + virtual std::string on_mustache_retrieve() override; StringOrHeader submit_to_redis (const boost::string_ref& parText, uint32_t parExpiry, const boost::string_ref& parLang); + + //TODO: remove, this shouldn't be in this class, nor on_mustache_prepare + //or on_mustache_retrieve. + std::string m_redirect_to; }; } //namespace tawashi