From 40735bb1229ae0369e7d763964ffbe543334b7c9 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 19 Apr 2020 15:59:07 +0200 Subject: Fix CGI i/o --- Makefile | 2 +- plugins/cgi/cgi.cpp | 13 +++++++------ response.cpp | 2 ++ webserver.conf | 5 ++++- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index d6c11f5..0d611e0 100644 --- a/Makefile +++ b/Makefile @@ -124,7 +124,7 @@ deb: dpkg-buildpackage -us -uc -rfakeroot deb-src: - dpkg-source -b . + dpkg-source -b -I.git -Iresult . $(DISTROS): deb-src sudo pbuilder build --basetgz /var/cache/pbuilder/$@.tgz --buildresult result/$@ ../webserver_$(VERSION).dsc diff --git a/plugins/cgi/cgi.cpp b/plugins/cgi/cgi.cpp index f5147c1..b8c2470 100644 --- a/plugins/cgi/cgi.cpp +++ b/plugins/cgi/cgi.cpp @@ -100,6 +100,8 @@ namespace { { "CONTENT-TYPE", [](std::string& v, CGIContext& c){ c.SetResponseHeader("content_type", v); } }, + { "SET-COOKIE", [](std::string& v, CGIContext& c){ c.SetResponseHeader("set_cookie", v); } }, + { "STATUS", [](std::string& v, CGIContext& c) { std::string status{"500"}; if (v.size() >= 3) { @@ -170,18 +172,17 @@ namespace { std::string executeFile(const fs::path& filename, CGIContext& context) { - bp::opstream is_in; + bp::pipe is_in; bp::ipstream is_out; - //std::cout << "Executing " << filename << std::endl; - bp::environment env {boost::this_process::environment()}; setCGIEnvironment(env, context); - bp::child child(filename.string(), env, (bp::std_out & bp::std_err) > is_out, bp::std_in < is_in); + bp::child child(filename.string(), env, bp::std_out > is_out, bp::std_err > stderr, bp::std_in < is_in); - is_in << context.GetRequestParam("body"); - //is_in.close(); + std::string body{ context.GetRequestParam("body") }; + is_in.write(body.data(), body.size()); + is_in.close(); std::string output; std::string line; diff --git a/response.cpp b/response.cpp index 97e2019..52081f6 100644 --- a/response.cpp +++ b/response.cpp @@ -181,6 +181,8 @@ void SetResponseHeader(const std::string& key, const std::string& value, respons res.set(http::field::location, value); } else if (key == "cache_control") { res.set(http::field::cache_control, value); + } else if (key == "set_cookie") { + res.set(http::field::set_cookie, value); } else throw std::runtime_error("Unsupported response field: "s + key); } diff --git a/webserver.conf b/webserver.conf index 1a5f5c8..f8238fd 100644 --- a/webserver.conf +++ b/webserver.conf @@ -13,7 +13,6 @@ lists.antcom.de antcom.de www.antcom.de - localhost ip6-localhost 127.0.0.1 [::1] @@ -49,6 +48,10 @@ static-files /home/ernie/homepage/test1 + + cgi + /home/ernie/code/webserver/cgi-bin + /home/ernie/code/webserver/cert.pem /home/ernie/code/webserver/key.pem -- cgit v1.2.3