diff --git a/conf/default.conf b/conf/default.conf index 2d57ca2..e1a3c0e 100644 --- a/conf/default.conf +++ b/conf/default.conf @@ -1,9 +1,10 @@ server { - listen 127.1.1.1:8080; + listen 0.0.0.0:8080; server_name localhost; root ./; autoindex on; - client_max_body_size 1000G; + client_max_body_size 10m; + index assets/index.html; use_chunked_encoding true; chunk_size 100; diff --git a/src/Config/ServerConfParse.cpp b/src/Config/ServerConfParse.cpp index 67d94b3..ddf9403 100644 --- a/src/Config/ServerConfParse.cpp +++ b/src/Config/ServerConfParse.cpp @@ -4,6 +4,7 @@ #include #include #include +#include static std::string cutEnding( std::string tmp ){ //if string ends on ; cut it @@ -111,10 +112,11 @@ void parseErrorPage( ServerConf& server, std::stringstream& ss ){ throw( std::runtime_error( "Line not ended on ; " + tmp ) ); } -int ParseSizeWithUnits(std::string str){ +size_t ParseSizeWithUnits(std::string str){ size_t multiplier = 1; char unit = str[str.size() -2]; // skip '0\ and ; + if (unit == 'K' || unit == 'k') { multiplier = 1024; // Kilobytes } else if (unit == 'M' || unit == 'm') { @@ -122,7 +124,8 @@ int ParseSizeWithUnits(std::string str){ } else if (unit == 'G' || unit == 'g') { multiplier = 1024 * 1024 * 1024; // Gigabytes } else if (!isdigit(unit)) { - return (-1); + throw( std::runtime_error( "Wrong Max Body Size" ) ); + return 0; } // Convert the numeric part of the string to a size_t @@ -130,23 +133,25 @@ int ParseSizeWithUnits(std::string str){ std::istringstream(str.substr(0, str.length() - (isdigit(unit) ? 0 : 1))) >> sizeValue; if (sizeValue == 0 && str[0] != '0') { - return(-1); + throw( std::runtime_error( "Wrong Max Body Size" ) ); + return 0; } - - return(sizeValue * multiplier); + + size_t result = sizeValue * multiplier; + return result; } void parseBodySize( ServerConf& server, std::stringstream& ss ){ std::string tmp; while( ss >> tmp ){ - int size; + size_t size; if( tmp.at( tmp.size() - 1 ) != ';' ) throw( std::runtime_error( "Line not ended on ; " + tmp ) ); + if(tmp[0] == '-'){ + throw( std::runtime_error( "negativ values not allowed " + tmp ) ); + } size = ParseSizeWithUnits(tmp); - //std::cout << "SSIZE " << size << "\n"; - if( size < 0) - throw( std::runtime_error( "Wrong Max Body Size" ) ); server.setBodySize( size ); } diff --git a/src/Response/post_Response.cpp b/src/Response/post_Response.cpp index 43097d6..cd98c71 100644 --- a/src/Response/post_Response.cpp +++ b/src/Response/post_Response.cpp @@ -32,7 +32,7 @@ int Response::checkContentLength(HttpRequest& ReqObj){ size_t maxBodySize = _serverConf->getBodySize(); //_locationConf->getClientMaxBodySize() : // If location config exists, use its limit->> dont have that parsed idk if we wna tto include //_serverConf->getClientMaxBodySize(); // Otherwise, use server's default limit - //std::cout << "C0ntent size " << contentLength << " and max body len " << maxBodySize << "\n"; + std::cout << "C0ntent size " << contentLength << " and max body len " << maxBodySize << "\n"; if (contentLength > maxBodySize) { throw 413; return 413;