@@ -221,48 +221,60 @@ namespace lklibs
221221 }
222222
223223 /* *
224- * @brief Ignore SSL errors when making HTTP requests
224+ * @brief Add a HTTP header to the request
225+ *
226+ * @param key: Header key
227+ * @param value: Header value
225228 */
226- HttpRequest& ignoreSslErrors ( ) noexcept
229+ HttpRequest& addHeader ( const std::string& key, const std::string& value ) noexcept
227230 {
228- this ->sslErrorsWillBeIgnored = true ;
231+ this ->headers [key] = value ;
229232
230233 return *this ;
231234 }
232235
233236 /* *
234- * @brief Set the TLS version for the request
237+ * @brief Set the timeout for the request
235238 *
236- * @param version: TLS version to be used for the request
239+ * @param timeout: Timeout in seconds (0 for no timeout)
237240 */
238- HttpRequest& setTLSVersion (TLSVersion version ) noexcept
241+ HttpRequest& setTimeout ( const int timeout ) noexcept
239242 {
240- this ->tlsVersion = version ;
243+ this ->timeout = timeout ;
241244
242245 return *this ;
243246 }
244247
245248 /* *
246- * @brief Add a HTTP header to the request
249+ * @brief Ignore SSL errors when making HTTP requests
250+ */
251+ HttpRequest& ignoreSslErrors () noexcept
252+ {
253+ this ->sslErrorsWillBeIgnored = true ;
254+
255+ return *this ;
256+ }
257+
258+ /* *
259+ * @brief Set the TLS version for the request
247260 *
248- * @param key: Header key
249- * @param value: Header value
261+ * @param version: TLS version to be used for the request
250262 */
251- HttpRequest& addHeader (const std::string& key, const std::string& value ) noexcept
263+ HttpRequest& setTLSVersion (const TLSVersion version ) noexcept
252264 {
253- this ->headers [key] = value ;
265+ this ->tlsVersion = version ;
254266
255267 return *this ;
256268 }
257269
258270 /* *
259- * @brief Set the timeout for the request
271+ * @brief Set the user agent for the request
260272 *
261- * @param timeout: Timeout in seconds (0 for no timeout)
273+ * @param userAgent: User agent to be used for the request
262274 */
263- HttpRequest& setTimeout ( int timeout ) noexcept
275+ HttpRequest& setUserAgent ( const std::string& userAgent ) noexcept
264276 {
265- this ->timeout = timeout ;
277+ this ->userAgent = userAgent ;
266278
267279 return *this ;
268280 }
@@ -272,7 +284,7 @@ namespace lklibs
272284 *
273285 * @param limit: Download bandwidth limit in bytes per second (0 for no limit)
274286 */
275- HttpRequest& setDownloadBandwidthLimit (int limit) noexcept
287+ HttpRequest& setDownloadBandwidthLimit (const int limit) noexcept
276288 {
277289 this ->downloadBandwidthLimit = limit;
278290
@@ -284,7 +296,7 @@ namespace lklibs
284296 *
285297 * @param limit: Upload bandwidth limit in bytes per second (0 for no limit)
286298 */
287- HttpRequest& setUploadBandwidthLimit (int limit) noexcept
299+ HttpRequest& setUploadBandwidthLimit (const int limit) noexcept
288300 {
289301 this ->uploadBandwidthLimit = limit;
290302
@@ -322,6 +334,7 @@ namespace lklibs
322334 std::string url;
323335 std::string method = " GET" ;
324336 std::string payload;
337+ std::string userAgent;
325338 bool sslErrorsWillBeIgnored = false ;
326339 ReturnFormat returnFormat = ReturnFormat::TEXT;
327340 std::map<std::string, std::string> headers;
@@ -386,6 +399,11 @@ namespace lklibs
386399 curl_easy_setopt (curl.get (), CURLOPT_MAX_SEND_SPEED_LARGE, this ->uploadBandwidthLimit );
387400 curl_easy_setopt (curl.get (), CURLOPT_MAX_RECV_SPEED_LARGE, this ->downloadBandwidthLimit );
388401
402+ if (!this ->userAgent .empty ())
403+ {
404+ curl_easy_setopt (curl.get (), CURLOPT_USERAGENT, this ->userAgent .c_str ());
405+ }
406+
389407 if (!this ->payload .empty ())
390408 {
391409 curl_easy_setopt (curl.get (), CURLOPT_POSTFIELDS, this ->payload .c_str ());
0 commit comments