Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions conf/default.conf
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
23 changes: 14 additions & 9 deletions src/Config/ServerConfParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdexcept>
#include <iostream>
#include <string>
#include <climits>

static std::string cutEnding( std::string tmp ){
//if string ends on ; cut it
Expand Down Expand Up @@ -111,42 +112,46 @@ 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') {
multiplier = 1024 * 1024; // Megabytes
} 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
size_t sizeValue = 0;
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 );
}

Expand Down
2 changes: 1 addition & 1 deletion src/Response/post_Response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down