diff options
Diffstat (limited to 'response.cpp')
-rw-r--r-- | response.cpp | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/response.cpp b/response.cpp index 78368f6..507b2d7 100644 --- a/response.cpp +++ b/response.cpp @@ -1,6 +1,10 @@ #include "response.h" #include "file.h" +#include <functional> + +using namespace std::placeholders; + namespace { // Append an HTTP rel-path to a local filesystem path. @@ -60,8 +64,39 @@ std::string extend_index_html(std::string path) return path; } -std::string generate_response(http::request<http::string_body>& req, const Config& config, const Socket& socket) +namespace { + +std::string GetServerParam(const std::string& key, Server& server) { + return ""; +} + +std::string GetRequestParam(const std::string& key, http::request<http::string_body>& req) +{ + return ""; +} + +void SetResponseHeader(const std::string& key, const std::string& value) +{ +} + +} + +std::string generate_response(http::request<http::string_body>& req, http::response<http::string_body>& res, Server& server) +{ +#if 0 + std::string host{req["host"]}; // TODO: just use string_view + std::string target{req.target()}; + std::string plugin_name { server.GetConfig().GetPlugin(server.GetSocket(), host, target)}; + plugin_type plugin{server.GetPlugin(plugin_name)}; + + auto GetServerParamFunction {std::function<std::string(const std::string& key)>(std::bind(GetServerParam, _1, std::ref(server)))}; + auto GetRequestParamFunction {std::function<std::string(const std::string& key)>(std::bind(GetRequestParam, _1, req))}; + auto SetResponseHeaderFunction{std::function<void(const std::string& key, const std::string& value)>(SetResponseHeader)}; + + return plugin->generate_page(GetServerParamFunction, GetRequestParamFunction, SetResponseHeaderFunction); + +#else // Make sure we can handle the method if( req.method() != http::verb::get && req.method() != http::verb::head) @@ -76,7 +111,7 @@ std::string generate_response(http::request<http::string_body>& req, const Confi // Build the path to the requested file std::string host{req["host"]}; // TODO: just use string_view std::string target{req.target()}; - std::string path = path_cat(config.DocRoot(socket, host, target), extend_index_html(std::string(req.target()))); + std::string path = path_cat(server.GetConfig().DocRoot(server.GetSocket(), host, target), extend_index_html(std::string(req.target()))); std::string result; try { @@ -88,5 +123,6 @@ std::string generate_response(http::request<http::string_body>& req, const Confi } return result; +#endif } |