Skip to content

Commit 91e9b31

Browse files
committed
Make head size limit a macro
1 parent 92a38cb commit 91e9b31

File tree

5 files changed

+26
-23
lines changed

5 files changed

+26
-23
lines changed

include/config/Config.hpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,46 +46,48 @@ const token_t tokens_g[] = {
4646
{"http", "_", true, 1, 1, 0, 0, NULL},
4747

4848
// Http context
49-
{"log_to_terminal", "http", false, 0, 1, 1, 1, isBoolean},
50-
{"log_level", "http", false, 0, 1, 1, 1, isLogLevel},
5149
{"access_log", "http", false, 0, 1, 1, 1, NULL},
52-
{"error_log", "http", false, 0, 1, 1, 1, NULL},
5350
{"cgi_timeout", "http", false, 0, 1, 1, 1, isNumeric},
5451
{"client_timeout", "http", false, 0, 1, 1, 1, isNumeric},
52+
{"error_log", "http", false, 0, 1, 1, 1, NULL},
53+
{"log_level", "http", false, 0, 1, 1, 1, isLogLevel},
54+
{"log_to_terminal", "http", false, 0, 1, 1, 1, isBoolean},
55+
{"server", "http", true, 1, static_cast<size_t>(-1), 0, 0, NULL},
56+
{"types", "http", true, 1, 1, 0, 0, NULL},
5557

5658
// Mime type context
57-
{"types", "http", true, 1, 1, 0, 0, NULL},
5859
{"type", "types", false, 1, static_cast<size_t>(-1), 2,
5960
static_cast<size_t>(-1), isMimeType},
6061

6162
// Server context
62-
{"server", "http", true, 1, static_cast<size_t>(-1), 0, 0, NULL},
63-
{"listen", "server", false, 1, static_cast<size_t>(-1), 1, 1, isListen},
64-
{"server_name", "server", false, 0, static_cast<size_t>(-1), 1,
65-
static_cast<size_t>(-1), NULL},
66-
{"root", "server", false, 1, 1, 1, 1, NULL},
67-
{"index", "server", false, 0, 1, 1, static_cast<size_t>(-1), NULL},
6863
{"allow", "server", false, 0, static_cast<size_t>(-1), 1,
6964
static_cast<size_t>(-1), isMethod},
7065
{"autoindex", "server", false, 0, 1, 1, 1, isBoolean},
71-
{"redirect", "server", false, 0, 1, 1, 1, NULL},
72-
{"max_client_body_size", "server", false, 0, 1, 1, 1, isMemorySize},
66+
{"cgi", "server", false, 0, static_cast<size_t>(-1), 2, 2, isCgi},
7367
{"error_page", "server", false, 0, static_cast<size_t>(-1), 2, 2,
7468
isErrorPage},
75-
{"cgi", "server", false, 0, static_cast<size_t>(-1), 2, 2, isCgi},
69+
{"index", "server", false, 0, 1, 1, static_cast<size_t>(-1), NULL},
70+
{"listen", "server", false, 1, static_cast<size_t>(-1), 1, 1, isListen},
71+
{"redirect", "server", false, 0, 1, 1, 1, NULL},
72+
{"root", "server", false, 1, 1, 1, 1, NULL},
73+
{"server_name", "server", false, 0, static_cast<size_t>(-1), 1,
74+
static_cast<size_t>(-1), NULL},
75+
{"max_client_head_size", "server", false, 0, 1, 1, 1, isMemorySize},
76+
{"max_client_body_size", "server", false, 0, 1, 1, 1, isMemorySize},
7677

7778
// Location context
78-
{"location", "server", true, 0, static_cast<size_t>(-1), 1, 1,
79-
isAbsolutePath},
8079
{"alias", "location", false, 0, 1, 1, 1, isAbsolutePath},
81-
{"root", "location", false, 0, 1, 1, 1, NULL},
82-
{"index", "location", false, 0, 1, 1, static_cast<size_t>(-1), NULL},
8380
{"allow", "location", false, 0, static_cast<size_t>(-1), 1,
8481
static_cast<size_t>(-1), isMethod},
8582
{"autoindex", "location", false, 0, 1, 1, 1, isBoolean},
86-
{"redirect", "location", false, 0, 1, 1, 1, NULL},
83+
{"cgi", "location", false, 0, static_cast<size_t>(-1), 2, 2, isCgi},
84+
{"index", "location", false, 0, 1, 1, static_cast<size_t>(-1), NULL},
85+
{"location", "server", true, 0, static_cast<size_t>(-1), 1, 1,
86+
isAbsolutePath},
8787
{"max_client_body_size", "location", false, 0, 1, 1, 1, isMemorySize},
88-
{"cgi", "location", false, 0, static_cast<size_t>(-1), 2, 2, isCgi}};
88+
{"max_client_head_size", "server", false, 0, 1, 1, 1, isMemorySize},
89+
{"redirect", "location", false, 0, 1, 1, 1, NULL},
90+
{"root", "location", false, 0, 1, 1, 1, NULL}};
8991

9092
class Config {
9193
private:

include/http/Http.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define HTTP_DEFAULT_METHODS \
1919
{ "GET", "HEAD", "OPTIONS" }
2020
#define HTTP_DEFAULT_MIME "application/octet-stream"
21+
#define MAX_CLIENT_HEAD_SIZE 16384
2122
#define MAX_CLIENT_BODY_SIZE 1048576
2223

2324
const std::string codes_g[] = {"200", "201", "204", "301", "400", "403", "404",

include/poll/AConnection.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class AConnection : public IFileDescriptor {
4545
Address client;
4646
Address host;
4747

48-
std::string::size_type headSizeLimit;
48+
std::string::size_type _maxHeadSize;
4949
std::string::size_type bodySize;
5050
size_t _writeBufferPos;
5151

src/http/Http.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Http::Http(Address const &client, Address const &host)
1010
: AConnection(host, client) {
1111
setReadState(REQUEST_LINE);
12-
this->headSizeLimit = 8192;
12+
this->_maxHeadSize = MAX_CLIENT_HEAD_SIZE;
1313
this->_virtualHost = NULL;
1414
this->_context = NULL;
1515
this->_expectedBodySize = 0;
@@ -84,7 +84,7 @@ void Http::OnHeadRecv(std::string msg) {
8484
void Http::OnChunkSizeRecv(std::string msg) {
8585
accessLog_g.write("HTTP chunk size: '" + msg + "'", VERBOSE);
8686

87-
msg.substr(0, msg.find(';'));
87+
(void)msg.substr(0, msg.find(';'));
8888
bodySize = 0;
8989
if (std::sscanf(msg.substr(0, msg.size()).c_str(), "%lx", &bodySize) == EOF) {
9090
errorLog_g.write("OnChunkSizeRecv(): sscanf failure", DEBUG, BRIGHT_RED);

src/poll/AConnection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ void AConnection::onPollIn(struct pollfd &pollfd) {
323323
if (pollfd.events & POLLIN &&
324324
(_readState == REQUEST_LINE || _readState == HEAD ||
325325
_readState == TRAILER) &&
326-
_readBuffer.size() > headSizeLimit) {
326+
_readBuffer.size() > _maxHeadSize) {
327327
pollfd.events = 0;
328328
pollfd.revents = 0;
329329
}

0 commit comments

Comments
 (0)