Skip to content
Snippets Groups Projects
Commit d44746f5 authored by Mathias Oppedal Heggelund's avatar Mathias Oppedal Heggelund
Browse files

Fix unvaldi HTTP-request error with a try catch in main.cpp

parent 260755ec
Branches
No related tags found
No related merge requests found
...@@ -9,8 +9,18 @@ int main() { ...@@ -9,8 +9,18 @@ int main() {
server.config.timeout_request = 0; server.config.timeout_request = 0;
// Response to all GET requests // Response to all GET requests
server.resource["^.*$"]["GET"] = [](std::shared_ptr<HttpServer::Response> response, std::shared_ptr<HttpServer::Request> /*request*/) { server.resource["^.*$"]["GET"] = [](std::shared_ptr<HttpServer::Response> response, std::shared_ptr<HttpServer::Request> request) {
try {
if(std::stof(request->http_version) >= 1.1) {
response->write("<h1>The web server is working!</h1>"); response->write("<h1>The web server is working!</h1>");
}
}
catch(std::invalid_argument &e) {
response->write(SimpleWeb::StatusCode::server_error_http_version_not_supported, "<h1>HTTP-version not valid (string)</h1>");
}
catch(std::out_of_range &e) {
response->write(SimpleWeb::StatusCode::server_error_http_version_not_supported, "<h1>HTTP-version not valid (out of range)</h1>");
}
}; };
server.start(); server.start();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment