summaryrefslogtreecommitdiffhomepage
path: root/response.cpp
diff options
context:
space:
mode:
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)))};