forked from love2d/lua-https
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHTTPS.cpp
83 lines (75 loc) · 1.81 KB
/
HTTPS.cpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "HTTPS.h"
#include "config.h"
#include "ConnectionClient.h"
#include "LibraryLoader.h"
#include <stdexcept>
#ifdef HTTPS_BACKEND_CURL
# include "../generic/CurlClient.h"
#endif
#ifdef HTTPS_BACKEND_OPENSSL
# include "../generic/OpenSSLConnection.h"
#endif
#ifdef HTTPS_BACKEND_SCHANNEL
# include "../windows/SChannelConnection.h"
#endif
#ifdef HTTPS_BACKEND_NSURL
# include "../apple/NSURLClient.h"
#endif
#ifdef HTTPS_BACKEND_ANDROID
# include "../android/AndroidClient.h"
#endif
#ifdef HTTPS_BACKEND_WININET
# include "../windows/WinINetClient.h"
#endif
#ifdef HTTPS_BACKEND_CURL
static CurlClient curlclient;
#endif
#ifdef HTTPS_BACKEND_OPENSSL
static ConnectionClient<OpenSSLConnection> opensslclient;
#endif
#ifdef HTTPS_BACKEND_SCHANNEL
static ConnectionClient<SChannelConnection> schannelclient;
#endif
#ifdef HTTPS_BACKEND_NSURL
static NSURLClient nsurlclient;
#endif
#ifdef HTTPS_BACKEND_ANDROID
static AndroidClient androidclient;
#endif
#ifdef HTTPS_BACKEND_WININET
static WinINetClient wininetclient;
#endif
static HTTPSClient *clients[] = {
#ifdef HTTPS_BACKEND_CURL
&curlclient,
#endif
#ifdef HTTPS_BACKEND_OPENSSL
&opensslclient,
#endif
// WinINet must be above SChannel
#ifdef HTTPS_BACKEND_WININET
&wininetclient,
#endif
#ifdef HTTPS_BACKEND_SCHANNEL
&schannelclient,
#endif
#ifdef HTTPS_BACKEND_NSURL
&nsurlclient,
#endif
#ifdef HTTPS_BACKEND_ANDROID
&androidclient,
#endif
nullptr,
};
// Call into the library loader to make sure it is linked in
static LibraryLoader::handle* dummyProcessHandle = LibraryLoader::GetCurrentProcessHandle();
HTTPSClient::Reply request(const HTTPSClient::Request &req)
{
for (size_t i = 0; clients[i]; ++i)
{
HTTPSClient &client = *clients[i];
if (client.valid())
return client.request(req);
}
throw std::runtime_error("No applicable HTTPS implementation found");
}