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