diff options
author | cflip <cflip@cflip.net> | 2022-09-17 11:20:47 -0600 |
---|---|---|
committer | cflip <cflip@cflip.net> | 2022-09-17 11:20:47 -0600 |
commit | a4140573844a83eda92367ae1e7d557b0033fb4d (patch) | |
tree | ffc111e9a31421fbe56beadf6e8a10f5a0f0d336 /src/main.cpp | |
parent | 105ebbce53ce3e28890c08961168dd21760676b9 (diff) |
Set a few environment variables for CGI scripts
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp index 2b93b07..4eb90bd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,6 +54,14 @@ static HttpResponse serve_from_cgi(const std::string& executable_path, HttpReque HttpResponse response; response.add_header("Server", "cfws"); + setenv("CONTENT_LENGTH", "0", true); + setenv("REQUEST_URI", request.uri().c_str(), true); + setenv("SCRIPT_NAME", executable_path.c_str(), true); + setenv("SCRIPT_FILENAME", executable_path.c_str(), true); + setenv("REQUEST_METHOD", "GET", true); + setenv("SERVER_PROTOCOL", "HTTP/1.1", true); + setenv("SERVER_SOFTWARE", "cfws/1.0-dev", true); + std::stringstream sstream; FILE* fp = popen(executable_path.c_str(), "r"); @@ -71,6 +79,14 @@ static HttpResponse serve_from_cgi(const std::string& executable_path, HttpReque pclose(fp); + unsetenv("CONTENT_LENGTH"); + unsetenv("REQUEST_URI"); + unsetenv("SCRIPT_NAME"); + unsetenv("SCRIPT_FILENAME"); + unsetenv("REQUEST_METHOD"); + unsetenv("SERVER_PROTOCOL"); + unsetenv("SERVER_SOFTWARE"); + // TODO: We should be able to construct a repsonse from an entire string // instead of always needing to individually set headers and content. response.set_status_code(HttpStatusCode::OK); |