summaryrefslogtreecommitdiff
path: root/libcurl/rest.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <shieldwed@outlook.com>2020-02-23 22:12:27 +0000
committerDaniel Wilhelm <shieldwed@outlook.com>2020-02-23 22:12:27 +0000
commit450f803dd75f831f8ee14072fe0eb664bbe518df (patch)
treeb3e831d44df50348a20f3541b6062f7fbab6ff3d /libcurl/rest.h
parentMerge branch '10.19' into 'master' (diff)
parentremove upstream deleted files (diff)
downloadFreeFileSync-450f803dd75f831f8ee14072fe0eb664bbe518df.tar.gz
FreeFileSync-450f803dd75f831f8ee14072fe0eb664bbe518df.tar.bz2
FreeFileSync-450f803dd75f831f8ee14072fe0eb664bbe518df.zip
Merge branch '10.20' into 'master'10.20
add upstream 10.20 See merge request opensource-tracking/FreeFileSync!17
Diffstat (limited to 'libcurl/rest.h')
-rw-r--r--libcurl/rest.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/libcurl/rest.h b/libcurl/rest.h
new file mode 100644
index 00000000..df41a3cc
--- /dev/null
+++ b/libcurl/rest.h
@@ -0,0 +1,52 @@
+// *****************************************************************************
+// * This file is part of the FreeFileSync project. It is distributed under *
+// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
+// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
+// *****************************************************************************
+
+#ifndef REST_H_07018456781346523454
+#define REST_H_07018456781346523454
+
+#include <chrono>
+#include <functional>
+#include <zen/sys_error.h>
+#include <zen/zstring.h>
+#include "curl_wrap.h" //DON'T include <curl/curl.h> directly!
+
+
+namespace zen
+{
+//Initialization requirement: 1. WSAStartup 2. OpenSSL 3. curl_global_init()
+// => use UniCounterCookie!
+
+class HttpSession
+{
+public:
+ HttpSession(const Zstring& server, const Zstring& caCertFilePath, std::chrono::seconds timeOut); //throw SysError
+ ~HttpSession();
+
+ struct Result
+ {
+ int statusCode = 0;
+ //std::string contentType;
+ };
+ Result perform(const std::string& serverRelPath,
+ const std::vector<std::string>& extraHeaders, const std::vector<CurlOption>& extraOptions, //throw SysError
+ const std::function<void (const void* buffer, size_t bytesToWrite)>& writeResponse /*throw X*/, //optional
+ const std::function<size_t( void* buffer, size_t bytesToRead )>& readRequest /*throw X*/); //
+
+ std::chrono::steady_clock::time_point getLastUseTime() const { return lastSuccessfulUseTime_; }
+
+private:
+ HttpSession (const HttpSession&) = delete;
+ HttpSession& operator=(const HttpSession&) = delete;
+
+ const std::string server_;
+ const std::string caCertFilePath_;
+ const std::chrono::seconds timeOutSec_;
+ CURL* easyHandle_ = nullptr;
+ std::chrono::steady_clock::time_point lastSuccessfulUseTime_ = std::chrono::steady_clock::now();
+};
+}
+
+#endif //REST_H_07018456781346523454
bgstack15