From d60a57f4475ffc7079dbad47d48bf6b3de1d3dce Mon Sep 17 00:00:00 2001 From: Mathias Oppedal Heggelund <mathiaoh@stud.ntnu.no> Date: Mon, 24 Aug 2020 12:58:32 +0200 Subject: [PATCH] Fix unvalid HTTP-request error with try catch server_http.hpp --- server_http.hpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/server_http.hpp b/server_http.hpp index c6402f5..bd4b7dc 100644 --- a/server_http.hpp +++ b/server_http.hpp @@ -762,10 +762,19 @@ 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(std::invalid_argument &e) { + std::cout << "HTTP version not valid (string)"; + } + catch(std::out_of_range &e) { + std::cout << "HTTP version not valid (out of range)"; } } else if(this->on_error) -- GitLab