diff --git a/CMakeLists.txt b/CMakeLists.txt index 23b8e8c..9eea334 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,10 +3,10 @@ cmake_minimum_required(VERSION 3.25) project(Rum VERSION 1.0) # compiler setup -set(CMAKE_C_COMPILER clang) -set(CMAKE_CXX_COMPILER clang++) +set(CMAKE_C_COMPILER gcc) +set(CMAKE_CXX_COMPILER g++) -set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_EXPORT_COMPILE_COMMANDS true) @@ -44,4 +44,4 @@ install(TARGETS ARCHIVE COMPONENT Development ) -install(DIRECTORY ${HEADERS} DESTINATION include COMPONENT Development) \ No newline at end of file +install(DIRECTORY ${HEADERS} DESTINATION include COMPONENT Development) diff --git a/src/rum/http/method.cpp b/src/rum/http/method.cpp index decdeed..1699541 100644 --- a/src/rum/http/method.cpp +++ b/src/rum/http/method.cpp @@ -19,6 +19,8 @@ std::string to_string(Method method) { return "OPTIONS"; case TRACE: return "TRACE"; + default: + return ""; } } } // namespace Rum::HTTP diff --git a/src/rum/http/request.cpp b/src/rum/http/request.cpp index cb19e6a..5a5b861 100644 --- a/src/rum/http/request.cpp +++ b/src/rum/http/request.cpp @@ -16,6 +16,9 @@ Request::operator std::string() const { for (auto cookie : cookies) { cookie_string += "\t\t'" + cookie.first + "': '" + cookie.second + "'\n"; } +#if __cplusplus < 202302L + return ""; +#else return std::vformat( "Request{{\n" "\tmethod: {}\n" @@ -25,6 +28,7 @@ Request::operator std::string() const { "\tbody: '{}'\n" "}}", std::make_format_args(to_string(method), (std::string)uri, headers_string, cookie_string, body)); +#endif } std::ostream& operator<<(std::ostream& stream, const Request req) { diff --git a/src/rum/http/response.cpp b/src/rum/http/response.cpp index 7cc56b9..cb72b99 100644 --- a/src/rum/http/response.cpp +++ b/src/rum/http/response.cpp @@ -72,7 +72,7 @@ std::string to_string(int code) { try { return codes.at(code); - } catch (std::out_of_range) { + } catch (std::out_of_range&) { return codes.at((code / 100) * 100); } } @@ -85,13 +85,19 @@ Response::~Response() { for (Cookie& cookie : cookies) { headers_string += "Set-cookie: " + (std::string)cookie + "\r\n"; } - +#if __cplusplus < 202302L + std::string message = + "HTTP/1.1 "+std::to_string(code)+" "+to_string(code)+"\r\n"+ + headers_string + "\r\n"+ + body; +#else std::string message = std::vformat( "HTTP/1.1 {} {}\r\n" "{}" "\r\n" "{}", std::make_format_args(std::to_string(code), to_string(code), headers_string, body)); +#endif send(client_sock, message.c_str(), message.size(), 0); } -} // namespace Rum::HTTP \ No newline at end of file +} // namespace Rum::HTTP diff --git a/src/rum/http/server.cpp b/src/rum/http/server.cpp index 232cfa2..51eec9d 100644 --- a/src/rum/http/server.cpp +++ b/src/rum/http/server.cpp @@ -119,7 +119,11 @@ void Server::handler(int client_sock, const sockaddr_in& client_address, char* b message += std::string(buffer, buffer + recieved); +#if __cplusplus < 202302L + if (stage == METHOD && message.find("\r\n") != message.npos) { +#else if (stage == METHOD && message.contains("\r\n")) { +#endif std::regex method_regex("(GET|HEAD|POST|PUT|DELETE|CONNECT|OPTIONS|TRACE) (\\/.*) HTTP.*"); std::smatch match; if (std::regex_match(message.cbegin(), message.cbegin() + message.find("\r\n"), match, method_regex)) { @@ -136,7 +140,11 @@ void Server::handler(int client_sock, const sockaddr_in& client_address, char* b } } +#if __cplusplus < 202302L + if (stage == HEADER && message.find("\r\n\r\n") != message.npos) { +#else if (stage == HEADER && message.contains("\r\n\r\n")) { +#endif std::regex header_regex("(.*): (.*)"); for (std::sregex_iterator it = std::sregex_iterator(message.cbegin(), message.cbegin() + message.find("\r\n\r\n"), header_regex); it != std::sregex_iterator(); it++) { @@ -176,15 +184,12 @@ void Server::handler(int client_sock, const sockaddr_in& client_address, char* b } if (stage == BODY) { - std::cout << "here" << std::endl; - try { size_t content_length = std::stoul(request.get_header("content-length")); - std::cout << message.size() << " " << content_length << std::endl; if (message.size() < content_length) continue; - } catch (std::out_of_range) { - } catch (std::invalid_argument e) { + } catch (std::out_of_range&) { + } catch (std::invalid_argument& e) { std::cerr << "invlaid Content-Length header" << std::endl; } request.set_body(message); @@ -210,8 +215,8 @@ void Server::handler(int client_sock, const sockaddr_in& client_address, char* b resp.set_code(404); resp.body = "