summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcflip <cflip@cflip.net>2022-09-19 14:56:20 -0600
committercflip <cflip@cflip.net>2022-09-19 14:56:20 -0600
commit0db641014f9163df475018a618ceb8bdb01250d1 (patch)
tree176afa24afdf8a5e3b0f966dc75ea49f70e29598
parent2ef8197a75c3d7605279b6c41c2eb3e1643d5374 (diff)
Implement the PATH_INFO and QUERY_STRING CGI environment variables
This allows scripts to differentiate between the requested path and the query parameters.
-rw-r--r--src/main.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp
index cd338b2..481dc41 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -55,10 +55,21 @@ static HttpResponse serve_from_cgi(const std::string& script_path, HttpRequest r
HttpResponse response;
response.add_header("Server", "cfws");
+ // Split URI between the path and the query parameter string
+ std::stringstream uri_stream(request.uri());
+ std::string segment;
+ std::vector<std::string> segment_list;
+
+ while (std::getline(uri_stream, segment, '?')) {
+ segment_list.push_back(segment);
+ }
+
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("PATH_INFO", segment_list[0].c_str());
+ if (segment_list.size() > 1)
+ script.set_environment("QUERY_STRING", segment_list[1].c_str());
script.set_environment("CONTENT_LENGTH", "0");
if (!script.open()) {