forked from cryfs/cryfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCurlHttpClient.h
More file actions
48 lines (34 loc) · 1.13 KB
/
CurlHttpClient.h
File metadata and controls
48 lines (34 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once
#ifndef MESSMER_CPPUTILS_NETWORK_CURLHTTPCLIENT_HPP
#define MESSMER_CPPUTILS_NETWORK_CURLHTTPCLIENT_HPP
#if !defined(_MSC_VER)
#include "HttpClient.h"
#include "../macros.h"
#include <mutex>
#include <curl/curl.h>
namespace cpputils {
class CurlHttpClient final : public HttpClient {
public:
CurlHttpClient();
~CurlHttpClient();
std::string get(const std::string &url, boost::optional<long> timeoutMsec = boost::none) override;
private:
// When the first object of this class is created, it will initialize curl using curl_global_init().
// When the last object is destroyed, it will deinitialize curl using curl_global_cleanup().
class CurlInitializerRAII final {
public:
CurlInitializerRAII();
~CurlInitializerRAII();
private:
static std::mutex _mutex;
static uint32_t _refcount;
DISALLOW_COPY_AND_ASSIGN(CurlInitializerRAII);
};
CurlInitializerRAII curlInitializer;
CURL *curl;
static size_t write_data(void *ptr, size_t size, size_t nmemb, std::ostringstream *stream);
DISALLOW_COPY_AND_ASSIGN(CurlHttpClient);
};
}
#endif
#endif