Skip to content

Instantly share code, notes, and snippets.

@Romain-P
Created March 9, 2019 16:53
Show Gist options
  • Save Romain-P/035c8207d276417465b0231c4bf5abb2 to your computer and use it in GitHub Desktop.
Save Romain-P/035c8207d276417465b0231c4bf5abb2 to your computer and use it in GitHub Desktop.
environment buildCgiEnvironment(Request &request) {
boost::process::environment cgi_env = boost::this_process::environment();
cgi_env["SCRIPT_FILENAME"] = "." + request.uri;
cgi_env["SERVER_PROTOCOL"] = request.protocol;
cgi_env["REQUEST_METHOD"] = request.method;
cgi_env["GATEWAY_INTERFACE"] = "CGI/1.1";
cgi_env["REDIRECT_STATUS"] = "200";
return cgi_env;
}
HookResultType onRequest(const Connection &connection, const Request &request, Response &response) override {
ipstream pipe_stream;
child c(_phpBinaryPath, std_out > pipe_stream, buildCgiEnvironment());
std::string line;
while (pipe_stream && std::getline(pipe_stream, line))
std::cerr << line << std::endl;
c.wait();
return HookResult::Ok;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment