Skip to content

Commit

Permalink
Merge pull request #49 from FreddyMSchubert/47-loop-per-ticks-for-dat…
Browse files Browse the repository at this point in the history
…atransfer

shits working 🍌
  • Loading branch information
NoelSabia authored Dec 16, 2024
2 parents c5ad19e + bd62c58 commit 3bbe340
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions include/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Config
void parseServerName(const std::string & line);
void parseRoot(const std::string & line);
void parseIndex(const std::string & line);
void parseClientMaxBodySize(const std::string & line);
void parsemaxPackageSize(const std::string & line);
void parseErrorPage(const std::string & line);
void parseClientTimeout(const std::string & line);

Expand Down Expand Up @@ -77,7 +77,7 @@ class Config
int getPort() const { return _port; }
std::string getRootDir() const { return _root_dir; }
FilePath getIndexFile() const { return *_index_file; }
unsigned int getClientMaxBodySize() const { return _client_max_body_size; }
unsigned int getmaxPackageSize() const { return _client_max_body_size; }
std::map<int, FilePath> getErrorPages() const { return _error_pages; }
int getClientTimeout() const { return _client_timeout; }
std::vector<t_location> getLocations() const { return _locations; }
Expand Down
4 changes: 2 additions & 2 deletions src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Config::Config(std::string data)

// 2. parse each line, based on starting keyword
std::array<std::string, CONFIG_KEYWORD_COUNT> keywords = {"listen", "server_name", "root", "index", "client_max_body_size", "error_page", "location", "client_timeout"};
std::array<void (Config::*)(const std::string&), CONFIG_KEYWORD_COUNT> parsers = {&Config::parseListen, &Config::parseServerName, &Config::parseRoot, &Config::parseIndex, &Config::parseClientMaxBodySize, &Config::parseErrorPage, &Config::parseLocation, &Config::parseClientTimeout};
std::array<void (Config::*)(const std::string&), CONFIG_KEYWORD_COUNT> parsers = {&Config::parseListen, &Config::parseServerName, &Config::parseRoot, &Config::parseIndex, &Config::parsemaxPackageSize, &Config::parseErrorPage, &Config::parseLocation, &Config::parseClientTimeout};
for (std::string &line : lines)
{
std::string keyword = line.substr(0, line.find(' '));
Expand Down Expand Up @@ -138,7 +138,7 @@ void Config::parseIndex(const std::string & line)
#endif
}

void Config::parseClientMaxBodySize(const std::string & line)
void Config::parsemaxPackageSize(const std::string & line)
{
std::regex size_regex(R"(client_max_body_size\s+(\d+)\s*([KMG]?B);)", std::regex::icase);
std::smatch match;
Expand Down
2 changes: 1 addition & 1 deletion src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bool Server::isDataComplete(t_socket_data &socket)
std::string data = socket.buffer.str();

// Step 1: Ensure buffer is not giant
if (data.size() > _config.getClientMaxBodySize())
if (data.size() > _config.getmaxPackageSize())
throw std::runtime_error("Client data size exceeded maximum body size");

size_t headerEnd = data.find("\r\n\r\n");
Expand Down
2 changes: 1 addition & 1 deletion src/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void Socket::sendData(Response &response)
std::string Socket::receiveData()
{
std::string data;
int size = std::min(1024, static_cast<int>(_config.getClientMaxBodySize() + 1));
int size = std::min(1024, static_cast<int>(_config.getmaxPackageSize() + 1));
char buffer[size];
ssize_t received;

Expand Down

0 comments on commit 3bbe340

Please sign in to comment.