diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e4187e1..34c2777 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,6 +18,7 @@ add_executable(${PROJECT_NAME} cgi_post.cpp curl_wrapper.cpp index_response.cpp + pastie_response.cpp ) target_include_directories(${PROJECT_NAME} SYSTEM diff --git a/src/main.cpp b/src/main.cpp index d3b568f..c71f81a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,6 @@ #include "incredis/incredis.hpp" #include "submit_paste_response.hpp" +#include "pastie_response.hpp" #include "index_response.hpp" #include "cgi_env.hpp" #include @@ -26,8 +27,8 @@ int main() { resp.send(); } else { - std::cout << "Content-type:text/plain\n\n"; - std::cout << "you shouldn't be here\n"; + tawashi::PastieResponse resp(incredis); + resp.send(); } return 0; diff --git a/src/pastie_response.cpp b/src/pastie_response.cpp new file mode 100644 index 0000000..f828135 --- /dev/null +++ b/src/pastie_response.cpp @@ -0,0 +1,26 @@ +#include "pastie_response.hpp" +#include "incredis/incredis.hpp" +#include + +namespace tawashi { + PastieResponse::PastieResponse (redis::IncRedis& parRedis) : + Response("text/plain"), + m_redis(parRedis) + { + } + + void PastieResponse::on_send (std::ostream& parStream) { + using opt_string = redis::IncRedis::opt_string; + + if (cgi_env().path_info().empty()) { + return; + } + + auto token = boost::string_ref(cgi_env().path_info()).substr(1); + opt_string pastie = m_redis.get(token); + if (not pastie) { + } + + parStream << *pastie; + } +} //namespace tawashi diff --git a/src/pastie_response.hpp b/src/pastie_response.hpp new file mode 100644 index 0000000..ce13ce7 --- /dev/null +++ b/src/pastie_response.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include "response.hpp" +#include + +namespace redis { + class IncRedis; +} //namespace redis + +namespace tawashi { + class PastieResponse : public Response { + public: + PastieResponse (redis::IncRedis& parRedis); + + private: + virtual void on_send (std::ostream& parStream) override; + + redis::IncRedis& m_redis; + }; +} //namespace tawashi