diff --git a/src/index_response.cpp b/src/index_response.cpp index 8cd023a..652d8d5 100644 --- a/src/index_response.cpp +++ b/src/index_response.cpp @@ -16,23 +16,26 @@ */ #include "index_response.hpp" +#include namespace tawashi { - IndexResponse::IndexResponse() : - Response(Response::ContentType, "text/html") + IndexResponse::IndexResponse (const boost::string_ref& parBaseURI) : + Response(Response::ContentType, "text/html", parBaseURI) { } void IndexResponse::on_send (std::ostream& parStream) { - parStream << - R"( + std::string html(R"(


-)"; +)"); + + boost::replace_all(html, "{base_uri}", base_uri()); + parStream << html; } } //namespace tawashi diff --git a/src/index_response.hpp b/src/index_response.hpp index f127e6a..ea8dede 100644 --- a/src/index_response.hpp +++ b/src/index_response.hpp @@ -18,11 +18,12 @@ #pragma once #include "response.hpp" +#include namespace tawashi { class IndexResponse : public Response { public: - IndexResponse(); + explicit IndexResponse (const boost::string_ref& parBaseURI); private: virtual void on_send (std::ostream& parStream) override; diff --git a/src/main.cpp b/src/main.cpp index ae412a4..1595f96 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -67,16 +67,17 @@ int main() { incredis.connect(); tawashi::cgi::Env cgi_env; + const boost::string_ref& base_uri = settings.at("base_uri"); if (cgi_env.path_info() == "/index.cgi") { - tawashi::IndexResponse resp; + tawashi::IndexResponse resp(base_uri); resp.send(); } else if (cgi_env.path_info() == "/paste.cgi") { - tawashi::SubmitPasteResponse resp(incredis); + tawashi::SubmitPasteResponse resp(incredis, base_uri); resp.send(); } else { - tawashi::PastieResponse resp(incredis); + tawashi::PastieResponse resp(incredis, base_uri); resp.send(); } diff --git a/src/pastie_response.cpp b/src/pastie_response.cpp index 81c0bfd..3934ddd 100644 --- a/src/pastie_response.cpp +++ b/src/pastie_response.cpp @@ -23,8 +23,8 @@ #include namespace tawashi { - PastieResponse::PastieResponse (redis::IncRedis& parRedis) : - Response(Response::ContentType, "text/html"), + PastieResponse::PastieResponse (redis::IncRedis& parRedis, const boost::string_ref& parBaseURI) : + Response(Response::ContentType, "text/html", parBaseURI), m_redis(parRedis), m_plain_text(false) { diff --git a/src/pastie_response.hpp b/src/pastie_response.hpp index 566d396..420b857 100644 --- a/src/pastie_response.hpp +++ b/src/pastie_response.hpp @@ -19,6 +19,7 @@ #include "response.hpp" #include +#include namespace redis { class IncRedis; @@ -27,7 +28,7 @@ namespace redis { namespace tawashi { class PastieResponse : public Response { public: - PastieResponse (redis::IncRedis& parRedis); + PastieResponse (redis::IncRedis& parRedis, const boost::string_ref& parBaseURI); private: virtual void on_process() override; diff --git a/src/response.cpp b/src/response.cpp index f327668..53b8ca2 100644 --- a/src/response.cpp +++ b/src/response.cpp @@ -20,8 +20,9 @@ #include namespace tawashi { - Response::Response (Types parRespType, std::string&& parValue) : + Response::Response (Types parRespType, std::string&& parValue, const boost::string_ref& parBaseURI) : m_resp_value(std::move(parValue)), + m_base_uri(parBaseURI), m_resp_type(parRespType), m_header_sent(false) { @@ -60,4 +61,8 @@ namespace tawashi { m_resp_type = parRespType; m_resp_value = std::move(parValue); } + + const boost::string_ref& Response::base_uri() const { + return m_base_uri; + } } //namespace tawashi diff --git a/src/response.hpp b/src/response.hpp index 083f3ad..3ca25e3 100644 --- a/src/response.hpp +++ b/src/response.hpp @@ -20,6 +20,7 @@ #include "cgi_env.hpp" #include #include +#include namespace tawashi { class Response { @@ -34,9 +35,10 @@ namespace tawashi { Location }; - Response (Types parRespType, std::string&& parValue); + Response (Types parRespType, std::string&& parValue, const boost::string_ref& parBaseURI); const cgi::Env& cgi_env() const; void change_type (Types parRespType, std::string&& parValue); + const boost::string_ref& base_uri() const; private: virtual void on_process(); @@ -44,6 +46,7 @@ namespace tawashi { cgi::Env m_cgi_env; std::string m_resp_value; + boost::string_ref m_base_uri; Types m_resp_type; bool m_header_sent; }; diff --git a/src/submit_paste_response.cpp b/src/submit_paste_response.cpp index a7e1343..cc00ec7 100644 --- a/src/submit_paste_response.cpp +++ b/src/submit_paste_response.cpp @@ -27,8 +27,8 @@ namespace tawashi { const char g_post_key[] = "pastie"; } //unnamed namespace - SubmitPasteResponse::SubmitPasteResponse (redis::IncRedis& parRedis) : - Response(Response::ContentType, "text/plain"), + SubmitPasteResponse::SubmitPasteResponse (redis::IncRedis& parRedis, const boost::string_ref& parBaseURI) : + Response(Response::ContentType, "text/plain", parBaseURI), m_redis(parRedis) { } diff --git a/src/submit_paste_response.hpp b/src/submit_paste_response.hpp index 78de7f3..de491ba 100644 --- a/src/submit_paste_response.hpp +++ b/src/submit_paste_response.hpp @@ -28,7 +28,7 @@ namespace redis { namespace tawashi { class SubmitPasteResponse : public Response { public: - explicit SubmitPasteResponse (redis::IncRedis& parRedis); + SubmitPasteResponse (redis::IncRedis& parRedis, const boost::string_ref& parBaseURI); private: virtual void on_process() override;