From 68d9cd4aeabecc54228812a54311dcd663b72dc8 Mon Sep 17 00:00:00 2001 From: randi <randeggu@stud.ntnu.no> Date: Mon, 24 Aug 2020 18:40:19 +0200 Subject: [PATCH] Added try catch when converting the http_version to a float. Should replace std::cout with error handling in the future. --- server_http.hpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/server_http.hpp b/server_http.hpp index c6402f5..f3c0d53 100644 --- a/server_http.hpp +++ b/server_http.hpp @@ -762,10 +762,16 @@ namespace SimpleWeb { return; } } - if(std::stof(response->session->request->http_version) >= 1.1) { - auto new_session = std::make_shared<Session>(this->config.max_request_streambuf_size, response->session->connection); - this->read(new_session); - return; + try { + if(std::stof(response->session->request->http_version) >= 1.1) { + auto new_session = std::make_shared<Session>(this->config.max_request_streambuf_size, response->session->connection); + this->read(new_session); + return; + } + } catch (const std::invalid_argument& ia){ + std::cout << "Invalid argument in HTTP version number " << ia.what() << std::endl; + } catch (const std::out_of_range& oor){ + std::cout << "Out of range in HTTP version number " << oor.what() << std::endl; } } else if(this->on_error) -- GitLab