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
40 changes: 21 additions & 19 deletions include/config/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(-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<size_t>(-1), 2,
static_cast<size_t>(-1), isMimeType},

// Server context
{"server", "http", true, 1, static_cast<size_t>(-1), 0, 0, NULL},
{"listen", "server", false, 1, static_cast<size_t>(-1), 1, 1, isListen},
{"server_name", "server", false, 0, static_cast<size_t>(-1), 1,
static_cast<size_t>(-1), NULL},
{"root", "server", false, 1, 1, 1, 1, NULL},
{"index", "server", false, 0, 1, 1, static_cast<size_t>(-1), NULL},
{"allow", "server", false, 0, static_cast<size_t>(-1), 1,
static_cast<size_t>(-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<size_t>(-1), 2, 2, isCgi},
{"error_page", "server", false, 0, static_cast<size_t>(-1), 2, 2,
isErrorPage},
{"cgi", "server", false, 0, static_cast<size_t>(-1), 2, 2, isCgi},
{"index", "server", false, 0, 1, 1, static_cast<size_t>(-1), NULL},
{"listen", "server", false, 1, static_cast<size_t>(-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<size_t>(-1), 1,
static_cast<size_t>(-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<size_t>(-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<size_t>(-1), NULL},
{"allow", "location", false, 0, static_cast<size_t>(-1), 1,
static_cast<size_t>(-1), isMethod},
{"autoindex", "location", false, 0, 1, 1, 1, isBoolean},
{"redirect", "location", false, 0, 1, 1, 1, NULL},
{"cgi", "location", false, 0, static_cast<size_t>(-1), 2, 2, isCgi},
{"index", "location", false, 0, 1, 1, static_cast<size_t>(-1), NULL},
{"location", "server", true, 0, static_cast<size_t>(-1), 1, 1,
isAbsolutePath},
{"max_client_body_size", "location", false, 0, 1, 1, 1, isMemorySize},
{"cgi", "location", false, 0, static_cast<size_t>(-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:
Expand Down
1 change: 1 addition & 0 deletions include/http/Http.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion include/poll/AConnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/http/Http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/poll/AConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down