diff --git a/lib/inc/drogon/CacheMap.h b/lib/inc/drogon/CacheMap.h index aa75f547..8437a5c8 100755 --- a/lib/inc/drogon/CacheMap.h +++ b/lib/inc/drogon/CacheMap.h @@ -360,4 +360,5 @@ class CacheMap } } }; + } // namespace drogon diff --git a/lib/inc/drogon/HttpRequest.h b/lib/inc/drogon/HttpRequest.h index 8ca8f59e..f9cba9ed 100755 --- a/lib/inc/drogon/HttpRequest.h +++ b/lib/inc/drogon/HttpRequest.h @@ -111,10 +111,25 @@ class HttpRequest virtual void setContentTypeCodeAndCharacterSet(ContentType type, const std::string &charSet = "utf-8") = 0; virtual ContentType getContentTypeCode() = 0; - /// Create a request object. + /// The following methods are a series of factory methods that help users create request objects. + + /// Create a normal request with http method Get and version Http1.1. static HttpRequestPtr newHttpRequest(); + /// Create a http request with: + /// Method: Get + /// Version: Http1.1 + /// Content type: application/json, the @param data will be serialized into the content of the request. static HttpRequestPtr newHttpJsonRequest(const Json::Value &data); + /// Create a http request with: + /// Method: Post + /// Version: Http1.1 + /// Content type: application/x-www-form-urlencoded static HttpRequestPtr newHttpFormPostRequest(); + /// Create a http file upload request with: + /// Method: Post + /// Version: Http1.1 + /// Content type: multipart/form-data + /// The @param files represents pload files which will be transferred to the server via the multipart/form-data format static HttpRequestPtr newFileUploadRequest(const std::vector &files); virtual ~HttpRequest() {} }; diff --git a/lib/inc/drogon/HttpSimpleController.h b/lib/inc/drogon/HttpSimpleController.h index 0df3cf9b..163bedc6 100755 --- a/lib/inc/drogon/HttpSimpleController.h +++ b/lib/inc/drogon/HttpSimpleController.h @@ -30,6 +30,7 @@ } namespace drogon { + class HttpSimpleControllerBase : public virtual DrObjectBase { public: diff --git a/lib/inc/drogon/HttpViewBase.h b/lib/inc/drogon/HttpViewBase.h index 0dacef23..7a4be478 100755 --- a/lib/inc/drogon/HttpViewBase.h +++ b/lib/inc/drogon/HttpViewBase.h @@ -22,6 +22,7 @@ namespace drogon { + class HttpViewBase : virtual public DrObjectBase { public: @@ -33,4 +34,5 @@ class HttpViewBase : virtual public DrObjectBase protected: virtual HttpResponsePtr genHttpResponse(const HttpViewData &) = 0; }; + } // namespace drogon diff --git a/lib/inc/drogon/HttpViewData.h b/lib/inc/drogon/HttpViewData.h index 9819c490..7f15ab13 100755 --- a/lib/inc/drogon/HttpViewData.h +++ b/lib/inc/drogon/HttpViewData.h @@ -27,9 +27,11 @@ typedef std::unordered_map ViewDataMap; namespace drogon { +/// This class represents the data set displayed in views. class HttpViewData { public: + /// The function template is used to get an item in the data set by the @param key. template const T get(const std::string &key, T &&nullVal = T()) const { @@ -47,6 +49,8 @@ class HttpViewData } return nullVal; } + + /// Insert an item identified by the @param key into the data set; void insert(const std::string &key, any &&obj) { viewData_[key] = std::move(obj); @@ -55,6 +59,8 @@ class HttpViewData { viewData_[key] = obj; } + + /// Insert an item identified by the @param key into the data set; The item will be converted to a string. template void insertAsString(const std::string &key, T &&val) { @@ -62,6 +68,8 @@ class HttpViewData ss << val; viewData_[key] = ss.str(); } + + /// Insert a formated string identified by the @param key. void insertFormattedString(const std::string &key, const char *format, ...) { @@ -105,6 +113,7 @@ class HttpViewData viewData_[key] = std::move(strBuffer); } + /// Get the 'any' object by the @param key. any &operator[](const std::string &key) const { return viewData_[key]; @@ -113,4 +122,5 @@ class HttpViewData protected: mutable ViewDataMap viewData_; }; + } // namespace drogon