summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-04-19 15:59:07 +0200
committerRoland Reichwein <mail@reichwein.it>2020-04-19 15:59:07 +0200
commit40735bb1229ae0369e7d763964ffbe543334b7c9 (patch)
treebc85b49852549edcc3f45f976ce56f65f077a3e3
parentb8f80db4ec3a5e586903834f29ec50a265c0c1fa (diff)
Fix CGI i/o
-rw-r--r--Makefile2
-rw-r--r--plugins/cgi/cgi.cpp13
-rw-r--r--response.cpp2
-rw-r--r--webserver.conf5
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 @@
<host>lists.antcom.de</host>
<host>antcom.de</host>
<host>www.antcom.de</host>
- <host>localhost</host>
<host>ip6-localhost</host>
<host>127.0.0.1</host>
<host>[::1]</host>
@@ -49,6 +48,10 @@
<plugin>static-files</plugin>
<target>/home/ernie/homepage/test1</target>
</path>
+ <path requested="/cgi-bin">
+ <plugin>cgi</plugin>
+ <target>/home/ernie/code/webserver/cgi-bin</target>
+ </path>
<certpath>/home/ernie/code/webserver/cert.pem</certpath>
<keypath>/home/ernie/code/webserver/key.pem</keypath>
</site>