diff options
Diffstat (limited to 'src/CGIScript.cpp')
-rw-r--r-- | src/CGIScript.cpp | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/CGIScript.cpp b/src/CGIScript.cpp index 6bc62ce..c630459 100644 --- a/src/CGIScript.cpp +++ b/src/CGIScript.cpp @@ -4,24 +4,13 @@ #include <string> #include <sstream> -CGIScript::CGIScript(const std::string& path, const HttpRequest& request) +CGIScript::CGIScript(const std::string& script_path) + : m_script_path(script_path) { - set_environment("CONTENT_LENGTH", "0"); - set_environment("REQUEST_URI", request.uri().c_str()); - set_environment("PATH_INFO", request.uri().c_str()); - set_environment("SCRIPT_NAME", path.c_str()); - set_environment("SCRIPT_FILENAME", path.c_str()); - set_environment("REQUEST_METHOD", "GET"); + set_environment("SCRIPT_NAME", script_path.c_str()); + set_environment("SCRIPT_FILENAME", script_path.c_str()); set_environment("SERVER_PROTOCOL", "HTTP/1.1"); - set_environment("SERVER_SOFTWARE", "cfws/1.0-dev"); - - m_pipe = popen(path.c_str(), "r"); - if (!m_pipe) { - perror("cfws: popen"); - return; - } - - m_is_open = true; + set_environment("SERVER_SOFTWARE", "cfws"); } CGIScript::~CGIScript() @@ -38,6 +27,18 @@ void CGIScript::set_environment(const char* key, const char* value) setenv(key, value, true); } +bool CGIScript::open() +{ + m_pipe = popen(m_script_path.c_str(), "r"); + if (!m_pipe) { + perror("cfws: popen"); + return false; + } + + m_is_open = true; + return true; +} + std::string CGIScript::read_output() { std::stringstream sstream; |