diff --git a/include/config/Config.hpp b/include/config/Config.hpp index 00cf18e..71628aa 100644 --- a/include/config/Config.hpp +++ b/include/config/Config.hpp @@ -46,46 +46,48 @@ const token_t tokens_g[] = { {"http", "_", true, 1, 1, 0, 0, NULL}, // Http context - {"log_to_terminal", "http", false, 0, 1, 1, 1, isBoolean}, - {"log_level", "http", false, 0, 1, 1, 1, isLogLevel}, {"access_log", "http", false, 0, 1, 1, 1, NULL}, - {"error_log", "http", false, 0, 1, 1, 1, NULL}, {"cgi_timeout", "http", false, 0, 1, 1, 1, isNumeric}, {"client_timeout", "http", false, 0, 1, 1, 1, isNumeric}, + {"error_log", "http", false, 0, 1, 1, 1, NULL}, + {"log_level", "http", false, 0, 1, 1, 1, isLogLevel}, + {"log_to_terminal", "http", false, 0, 1, 1, 1, isBoolean}, + {"server", "http", true, 1, static_cast(-1), 0, 0, NULL}, + {"types", "http", true, 1, 1, 0, 0, NULL}, // Mime type context - {"types", "http", true, 1, 1, 0, 0, NULL}, {"type", "types", false, 1, static_cast(-1), 2, static_cast(-1), isMimeType}, // Server context - {"server", "http", true, 1, static_cast(-1), 0, 0, NULL}, - {"listen", "server", false, 1, static_cast(-1), 1, 1, isListen}, - {"server_name", "server", false, 0, static_cast(-1), 1, - static_cast(-1), NULL}, - {"root", "server", false, 1, 1, 1, 1, NULL}, - {"index", "server", false, 0, 1, 1, static_cast(-1), NULL}, {"allow", "server", false, 0, static_cast(-1), 1, static_cast(-1), isMethod}, {"autoindex", "server", false, 0, 1, 1, 1, isBoolean}, - {"redirect", "server", false, 0, 1, 1, 1, NULL}, - {"max_client_body_size", "server", false, 0, 1, 1, 1, isMemorySize}, + {"cgi", "server", false, 0, static_cast(-1), 2, 2, isCgi}, {"error_page", "server", false, 0, static_cast(-1), 2, 2, isErrorPage}, - {"cgi", "server", false, 0, static_cast(-1), 2, 2, isCgi}, + {"index", "server", false, 0, 1, 1, static_cast(-1), NULL}, + {"listen", "server", false, 1, static_cast(-1), 1, 1, isListen}, + {"redirect", "server", false, 0, 1, 1, 1, NULL}, + {"root", "server", false, 1, 1, 1, 1, NULL}, + {"server_name", "server", false, 0, static_cast(-1), 1, + static_cast(-1), NULL}, + {"max_client_head_size", "server", false, 0, 1, 1, 1, isMemorySize}, + {"max_client_body_size", "server", false, 0, 1, 1, 1, isMemorySize}, // Location context - {"location", "server", true, 0, static_cast(-1), 1, 1, - isAbsolutePath}, {"alias", "location", false, 0, 1, 1, 1, isAbsolutePath}, - {"root", "location", false, 0, 1, 1, 1, NULL}, - {"index", "location", false, 0, 1, 1, static_cast(-1), NULL}, {"allow", "location", false, 0, static_cast(-1), 1, static_cast(-1), isMethod}, {"autoindex", "location", false, 0, 1, 1, 1, isBoolean}, - {"redirect", "location", false, 0, 1, 1, 1, NULL}, + {"cgi", "location", false, 0, static_cast(-1), 2, 2, isCgi}, + {"index", "location", false, 0, 1, 1, static_cast(-1), NULL}, + {"location", "server", true, 0, static_cast(-1), 1, 1, + isAbsolutePath}, {"max_client_body_size", "location", false, 0, 1, 1, 1, isMemorySize}, - {"cgi", "location", false, 0, static_cast(-1), 2, 2, isCgi}}; + {"max_client_head_size", "server", false, 0, 1, 1, 1, isMemorySize}, + {"redirect", "location", false, 0, 1, 1, 1, NULL}, + {"root", "location", false, 0, 1, 1, 1, NULL}}; class Config { private: diff --git a/include/http/Http.hpp b/include/http/Http.hpp index 9682511..17ec408 100644 --- a/include/http/Http.hpp +++ b/include/http/Http.hpp @@ -18,6 +18,7 @@ #define HTTP_DEFAULT_METHODS \ { "GET", "HEAD", "OPTIONS" } #define HTTP_DEFAULT_MIME "application/octet-stream" +#define MAX_CLIENT_HEAD_SIZE 16384 #define MAX_CLIENT_BODY_SIZE 1048576 const std::string codes_g[] = {"200", "201", "204", "301", "400", "403", "404", diff --git a/include/poll/AConnection.hpp b/include/poll/AConnection.hpp index 71fc334..a203d4e 100644 --- a/include/poll/AConnection.hpp +++ b/include/poll/AConnection.hpp @@ -45,7 +45,7 @@ class AConnection : public IFileDescriptor { Address client; Address host; - std::string::size_type headSizeLimit; + std::string::size_type _maxHeadSize; std::string::size_type bodySize; size_t _writeBufferPos; diff --git a/src/http/Http.cpp b/src/http/Http.cpp index 9f3ba36..a353667 100644 --- a/src/http/Http.cpp +++ b/src/http/Http.cpp @@ -9,7 +9,7 @@ Http::Http(Address const &client, Address const &host) : AConnection(host, client) { setReadState(REQUEST_LINE); - this->headSizeLimit = 8192; + this->_maxHeadSize = MAX_CLIENT_HEAD_SIZE; this->_virtualHost = NULL; this->_context = NULL; this->_expectedBodySize = 0; @@ -84,7 +84,7 @@ void Http::OnHeadRecv(std::string msg) { void Http::OnChunkSizeRecv(std::string msg) { accessLog_g.write("HTTP chunk size: '" + msg + "'", VERBOSE); - msg.substr(0, msg.find(';')); + (void)msg.substr(0, msg.find(';')); bodySize = 0; if (std::sscanf(msg.substr(0, msg.size()).c_str(), "%lx", &bodySize) == EOF) { errorLog_g.write("OnChunkSizeRecv(): sscanf failure", DEBUG, BRIGHT_RED); diff --git a/src/poll/AConnection.cpp b/src/poll/AConnection.cpp index 525e394..1b208a6 100644 --- a/src/poll/AConnection.cpp +++ b/src/poll/AConnection.cpp @@ -323,7 +323,7 @@ void AConnection::onPollIn(struct pollfd &pollfd) { if (pollfd.events & POLLIN && (_readState == REQUEST_LINE || _readState == HEAD || _readState == TRAILER) && - _readBuffer.size() > headSizeLimit) { + _readBuffer.size() > _maxHeadSize) { pollfd.events = 0; pollfd.revents = 0; }