File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ class create_webserver
5252 _max_threads (0 ),
5353 _max_connections (0 ),
5454 _memory_limit (0 ),
55+ _content_size_limit (0 ),
5556 _connection_timeout (DEFAULT_WS_TIMEOUT),
5657 _per_IP_connection_limit (0 ),
5758 _log_access (0x0 ),
@@ -93,6 +94,7 @@ class create_webserver
9394 _max_threads(0 ),
9495 _max_connections(0 ),
9596 _memory_limit(0 ),
97+ _content_size_limit(0 ),
9698 _connection_timeout(DEFAULT_WS_TIMEOUT),
9799 _per_IP_connection_limit(0 ),
98100 _log_access(0x0 ),
@@ -147,6 +149,10 @@ class create_webserver
147149 {
148150 _memory_limit = memory_limit; return *this ;
149151 }
152+ create_webserver& content_size_limit (size_t content_size_limit)
153+ {
154+ _content_size_limit = content_size_limit; return *this ;
155+ }
150156 create_webserver& connection_timeout (int connection_timeout)
151157 {
152158 _connection_timeout = connection_timeout; return *this ;
@@ -333,6 +339,7 @@ class create_webserver
333339 int _max_threads;
334340 int _max_connections;
335341 int _memory_limit;
342+ size_t _content_size_limit;
336343 int _connection_timeout;
337344 int _per_IP_connection_limit;
338345 log_access_ptr _log_access;
Original file line number Diff line number Diff line change @@ -467,9 +467,14 @@ class http_request
467467 * @param content The content to append.
468468 * @param size The size of the data to append.
469469 **/
470- void grow_content (const char * content, size_t size)
470+ void grow_content (const char * content, size_t size,
471+ size_t content_size_limit)
471472 {
472473 this ->content .append (content, size);
474+ if (this ->content .size () > content_size_limit)
475+ {
476+ this ->content .resize (content_size_limit);
477+ }
473478 }
474479 /* *
475480 * Method used to set the path requested.
Original file line number Diff line number Diff line change @@ -179,6 +179,7 @@ class webserver
179179 const int max_threads;
180180 const int max_connections;
181181 const int memory_limit;
182+ const size_t content_size_limit;
182183 const int connection_timeout;
183184 const int per_IP_connection_limit;
184185 log_access_ptr log_access;
Original file line number Diff line number Diff line change @@ -141,6 +141,7 @@ webserver::webserver(const create_webserver& params):
141141 max_threads (params._max_threads),
142142 max_connections (params._max_connections),
143143 memory_limit (params._memory_limit),
144+ content_size_limit (params._content_size_limit),
144145 connection_timeout (params._connection_timeout),
145146 per_IP_connection_limit (params._per_IP_connection_limit),
146147 log_access (params._log_access),
@@ -698,7 +699,7 @@ int webserver::bodyfull_requests_answer_second_step(
698699#ifdef DEBUG
699700 cout << " Writing content: " << upload_data << endl;
700701#endif // DEBUG
701- mr->dhr ->grow_content (upload_data, *upload_data_size);
702+ mr->dhr ->grow_content (upload_data, *upload_data_size, content_size_limit );
702703
703704 if (mr->pp != NULL ) MHD_post_process (mr->pp , upload_data, *upload_data_size);
704705 *upload_data_size = 0 ;
You can’t perform that action at this time.
0 commit comments