From 2ef8197a75c3d7605279b6c41c2eb3e1643d5374 Mon Sep 17 00:00:00 2001 From: cflip Date: Mon, 19 Sep 2022 13:47:51 -0600 Subject: Refactor the CGIScript class a bit This allows the user of the class to set environment variables before opening the pipe to the script. --- src/main.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/main.cpp') 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!"); -- cgit v1.2.3