Created
March 9, 2019 16:53
-
-
Save Romain-P/035c8207d276417465b0231c4bf5abb2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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