@@ -310,6 +310,18 @@ class http_request
310310 {
311311 result = this ->content ;
312312 }
313+ /* *
314+ * Method to check whether the size of the content reached or exceeded content_size_limit.
315+ * @return boolean
316+ **/
317+ bool content_too_large () const
318+ {
319+ return content.size ()>=content_size_limit;
320+ }
321+ /* *
322+ * Method used to get the content of the query string..
323+ * @return the query string in string representation
324+ **/
313325 const std::string get_querystring () const
314326 {
315327 return this ->querystring ;
@@ -361,7 +373,7 @@ class http_request
361373 * Default constructor of the class. It is a specific responsibility of apis to initialize this type of objects.
362374 **/
363375 http_request ():
364- content (" " )
376+ content (" " ), content_size_limit( static_cast < size_t >(- 1 ))
365377 {
366378 }
367379 /* *
@@ -381,6 +393,7 @@ class http_request
381393 args (b.args),
382394 querystring (b.querystring),
383395 content (b.content),
396+ content_size_limit (b.content_size_limit),
384397 version (b.version),
385398 requestor (b.requestor),
386399 underlying_connection (b.underlying_connection)
@@ -398,6 +411,7 @@ class http_request
398411 std::map<std::string, std::string, http::arg_comparator> args;
399412 std::string querystring;
400413 std::string content;
414+ size_t content_size_limit;
401415 std::string version;
402416 std::string requestor;
403417
@@ -442,11 +456,7 @@ class http_request
442456 **/
443457 void set_arg (const std::string& key, const std::string& value)
444458 {
445- if (this ->args [key].empty ()) {
446- this ->args [key] = value;
447- } else {
448- this ->args [key].append (value);
449- }
459+ this ->args [key] = value.substr (0 ,content_size_limit);
450460 }
451461 /* *
452462 * Method used to set an argument value by key.
@@ -456,19 +466,24 @@ class http_request
456466 **/
457467 void set_arg (const char * key, const char * value, size_t size)
458468 {
459- if (this ->args [key].empty ()) {
460- this ->args [key] = std::string (value, size);
461- } else {
462- this ->args [key].append (value, size);
463- }
469+ this ->args [key] = std::string (value,
470+ std::min (size, content_size_limit));
464471 }
465472 /* *
466473 * Method used to set the content of the request
467474 * @param content The content to set.
468475 **/
469476 void set_content (const std::string& content)
470477 {
471- this ->content = content;
478+ this ->content = content.substr (0 ,content_size_limit);
479+ }
480+ /* *
481+ * Method used to set the maximum size of the content
482+ * @param content_size_limit The limit on the maximum size of the content and arg's.
483+ **/
484+ void set_content_size_limit (size_t content_size_limit)
485+ {
486+ this ->content_size_limit = content_size_limit;
472487 }
473488 /* *
474489 * Method used to append content to the request preserving the previous inserted content
@@ -478,6 +493,10 @@ class http_request
478493 void grow_content (const char * content, size_t size)
479494 {
480495 this ->content .append (content, size);
496+ if (this ->content .size () > content_size_limit)
497+ {
498+ this ->content .resize (content_size_limit);
499+ }
481500 }
482501 /* *
483502 * Method used to set the path requested.
@@ -568,7 +587,7 @@ class http_request
568587 {
569588 std::map<std::string, std::string>::const_iterator it;
570589 for (it = args.begin (); it != args.end (); ++it)
571- this ->args [it->first ] = it->second ;
590+ this ->args [it->first ] = it->second . substr ( 0 ,content_size_limit) ;
572591 }
573592 /* *
574593 * Method used to set the username of the request.
0 commit comments