diff options
author | cflip <cflip@cflip.net> | 2022-09-19 13:47:51 -0600 |
---|---|---|
committer | cflip <cflip@cflip.net> | 2022-09-19 13:48:33 -0600 |
commit | 2ef8197a75c3d7605279b6c41c2eb3e1643d5374 (patch) | |
tree | aebda710c6ac59132d47554fc5420e2ac6cc16d3 /src/main.cpp | |
parent | 91c237df6a65f6ec446eea4b89216ad53c9f7e0e (diff) |
Refactor the CGIScript class a bit
This allows the user of the class to set environment variables before
opening the pipe to the script.
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp index c24747e..cd338b2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -55,8 +55,13 @@ static HttpResponse serve_from_cgi(const std::string& script_path, HttpRequest r HttpResponse response; response.add_header("Server", "cfws"); - CGIScript script(script_path, request); - if (!script.is_open()) { + CGIScript script(script_path); + script.set_environment("REQUEST_METHOD", "GET"); + script.set_environment("REQUEST_URI", request.uri().c_str()); + script.set_environment("PATH_INFO", request.uri().c_str()); + script.set_environment("CONTENT_LENGTH", "0"); + + if (!script.open()) { response.set_status_code(HttpStatusCode::InternalServerError); response.add_header("Content-Type", "text/plain"); response.set_content("Failed to open CGI script!"); |