summaryrefslogtreecommitdiffhomepage
path: root/response.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-06-06 15:13:39 +0200
committerRoland Reichwein <mail@reichwein.it>2020-06-06 15:13:39 +0200
commit357cf76409d30341a2c4eedcf2568f0abd56e88d (patch)
treeaa9a6121fa9e7827b854ec4c744d60c4f1375e50 /response.cpp
parentc899a9cb581aa67be94231eba02f432a199512e7 (diff)
More runtime error checking
Diffstat (limited to 'response.cpp')
-rw-r--r--response.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/response.cpp b/response.cpp
index 4e66dd3..98abac4 100644
--- a/response.cpp
+++ b/response.cpp
@@ -224,7 +224,14 @@ std::unordered_map<std::string, std::function<void(const std::string&, response_
{ "location", [](const std::string& value, response_type& res){res.set(http::field::location, value);} },// e.g. 301 Moved Permanently: new Location
{ "server", [](const std::string& value, response_type& res){res.set(http::field::server, value);} }, // Server name/version string
{ "set_cookie", [](const std::string& value, response_type& res){res.set(http::field::set_cookie, value);} },
- { "status", [](const std::string& value, response_type& res){res.result(unsigned(stoul(value)));} }, // HTTP Status, e.g. "200" (OK)
+ { "status", [](const std::string& value, response_type& res){
+ try {
+ res.result(unsigned(stoul(value)));
+ } catch (...) {
+ std::cerr << "Error: Bad status value: " << value << std::endl;
+ res.result(400);
+ }
+ } }, // HTTP Status, e.g. "200" (OK)
{ "www_authenticate", [](const std::string& value, response_type& res){res.set(http::field::www_authenticate, value);} },
};
@@ -242,7 +249,12 @@ void SetResponseHeader(const std::string& key, const std::string& value, respons
response_type HttpStatus(std::string status, std::string message, response_type& res)
{
if (status != "200") { // already handled at res init
- res.result(unsigned(stoul(status)));
+ try {
+ res.result(unsigned(stoul(status)));
+ } catch (...) {
+ std::cerr << "Error: HttpStatus: Bad status value: " << status << std::endl;
+ res.result(400);
+ }
res.set(http::field::content_type, "text/html");
res.body() = "<html><body><h1>"s + Server::VersionString + " Error</h1><p>"s + status + " "s + message + "</p></body></html>"s;