From 791b90b9898cc41869538f1dfc303588436682b7 Mon Sep 17 00:00:00 2001 From: B Stack Date: Sat, 15 Feb 2020 11:50:31 -0500 Subject: add upstream 10.20 It is worth noting that the send email feature is not present in the GPL release. --- libcurl/rest.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 libcurl/rest.h (limited to 'libcurl/rest.h') 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 +#include +#include +#include +#include "curl_wrap.h" //DON'T include 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& extraHeaders, const std::vector& extraOptions, //throw SysError + const std::function& writeResponse /*throw X*/, //optional + const std::function& 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 -- cgit