summaryrefslogtreecommitdiffhomepage
path: root/response.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-04-11 13:17:32 +0200
committerRoland Reichwein <mail@reichwein.it>2020-04-11 13:17:32 +0200
commit6081819802972c716745a44e3521ccb3b3cf7b1a (patch)
treed1dafa4b821acff243f1613d2dd483e49782ff0b /response.cpp
parent07f01d1ab5e68fc042356fd90fa07c199791b29c (diff)
Support IPv6
Diffstat (limited to 'response.cpp')
-rw-r--r--response.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/response.cpp b/response.cpp
index 70c93b1..4d6aaaf 100644
--- a/response.cpp
+++ b/response.cpp
@@ -109,6 +109,17 @@ mime_type(beast::string_view path)
return "application/text";
}
+// Used to return errors by generating response page and HTTP status code
+response_type HttpStatus(std::string status, std::string message, response_type& res)
+{
+ res.result(unsigned(stoul(status)));
+ res.set(http::field::content_type, "text/html");
+ res.body() = "<html><body><h1>"s + VersionString + " Error</h1><p>"s + status + " "s + message + "</p></body></html>"s;
+ res.prepare_payload();
+
+ return res;
+}
+
} // anonymous namespace
response_type generate_response(request_type& req, Server& server)
@@ -121,6 +132,10 @@ response_type generate_response(request_type& req, Server& server)
std::string host{req["host"]};
std::string target{req.target()};
std::string plugin_name { server.GetConfig().GetPlugin(server.GetSocket(), host, target)};
+ if (plugin_name == "") {
+ return HttpStatus("400", "Bad request: Host "s + host + ":"s + target + " unknown"s, res);
+ }
+
plugin_type plugin{server.GetPlugin(plugin_name)};
auto GetServerParamFunction {std::function<std::string(const std::string& key)>(std::bind(GetServerParam, _1, std::ref(server)))};