From 6081819802972c716745a44e3521ccb3b3cf7b1a Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 11 Apr 2020 13:17:32 +0200 Subject: Support IPv6 --- response.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'response.cpp') 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() = "

"s + VersionString + " Error

"s + status + " "s + message + "

"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::bind(GetServerParam, _1, std::ref(server)))}; -- cgit v1.2.3