File size: 2,831 Bytes
bfd87b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
84
85
86
87
88
89
/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */


#pragma once

#include <aws/core/Core_EXPORTS.h>
#include <aws/core/http/HttpClient.h>
#include <aws/core/http/curl/CurlHandleContainer.h>
#include <aws/core/client/ClientConfiguration.h>
#include <aws/core/utils/memory/stl/AWSString.h>
#include <atomic>

namespace Aws
{
namespace Http
{
namespace Standard
{
    class StandardHttpResponse;
}

//Curl implementation of an http client. Right now it is only synchronous.
class AWS_CORE_API CurlHttpClient: public HttpClient
{
public:

    using Base = HttpClient;

    //Creates client, initializes curl handle if it hasn't been created already.
    CurlHttpClient(const Aws::Client::ClientConfiguration& clientConfig);

    //Makes request and receives response synchronously
    std::shared_ptr<HttpResponse> MakeRequest(const std::shared_ptr<HttpRequest>& request,
        Aws::Utils::RateLimits::RateLimiterInterface* readLimiter = nullptr,
        Aws::Utils::RateLimits::RateLimiterInterface* writeLimiter = nullptr) const override;

    static void InitGlobalState();
    static void CleanupGlobalState();

protected:
    /**
     * Override any configuration on CURL handle for each request before sending.
     * The usage is to have a subclass of CurlHttpClient and have your own implementation of this function to configure whatever you want on CURL handle.
     */
    virtual void OverrideOptionsOnConnectionHandle(CURL*) const {}

private:
    mutable CurlHandleContainer m_curlHandleContainer;
    bool m_isAllowSystemProxy = false;
    bool m_isUsingProxy = false;
    Aws::String m_proxyUserName;
    Aws::String m_proxyPassword;
    Aws::String m_proxyScheme;
    Aws::String m_proxyHost;
    Aws::String m_proxySSLCertPath;
    Aws::String m_proxySSLCertType;
    Aws::String m_proxySSLKeyPath;
    Aws::String m_proxySSLKeyType;
    Aws::String m_proxyKeyPasswd;
    unsigned m_proxyPort = 0;
    Aws::String m_nonProxyHosts;
    bool m_verifySSL = true;
    Aws::String m_caPath;
    Aws::String m_caFile;
    Aws::String m_proxyCaPath;
    Aws::String m_proxyCaFile;
    bool m_disableExpectHeader = false;
    bool m_allowRedirects = false;
    bool m_enableHttpClientTrace = false;
    Aws::Http::TransferLibPerformanceMode m_perfMode = TransferLibPerformanceMode::LOW_LATENCY;
    static std::atomic<bool> isInit;
    std::shared_ptr<smithy::components::tracing::TelemetryProvider> m_telemetryProvider;

#if LIBCURL_VERSION_NUM >= 0x072000 // 7.32.0
    static int CurlProgressCallback(void *userdata, curl_off_t, curl_off_t, curl_off_t, curl_off_t);
#else
    static int CurlProgressCallback(void *userdata, double, double, double, double);
#endif
};

using PlatformHttpClient = CurlHttpClient;

} // namespace Http
} // namespace Aws