Skip to content

Commit 853d3ff

Browse files
authored
feat: Implement http/https requests. (#27)
1 parent 0e3c1f2 commit 853d3ff

File tree

15 files changed

+764
-31
lines changed

15 files changed

+764
-31
lines changed

libs/client-sdk/src/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ file(GLOB HEADER_LIST CONFIGURE_DEPENDS
99
)
1010

1111
# Automatic library: static or dynamic based on user config.
12-
add_library(${LIBNAME} api.cpp ${HEADER_LIST}
12+
13+
add_library(${LIBNAME}
14+
api.cpp
15+
${HEADER_LIST}
1316
data_sources/streaming_data_source.cpp
1417
data_sources/base_64.cpp
1518
data_sources/streaming_data_handler.cpp

libs/common/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,20 @@ endif ()
2424
# Needed to fetch external dependencies.
2525
include(FetchContent)
2626

27+
set(OPENSSL_USE_STATIC_LIBS OFF)
28+
set(OPENSSL_ROOT_DIR "/opt/homebrew/opt/[email protected]")
29+
find_package(OpenSSL REQUIRED)
30+
message(STATUS "LaunchDarkly: using OpenSSL v${OPENSSL_VERSION}")
31+
2732
set(Boost_USE_STATIC_LIBS OFF)
2833
set(Boost_USE_MULTITHREADED ON)
2934
set(Boost_USE_STATIC_RUNTIME OFF)
30-
find_package(Boost 1.80 REQUIRED)
35+
find_package(Boost 1.80 REQUIRED COMPONENTS json url)
3136
message(STATUS "LaunchDarkly: using Boost v${Boost_VERSION}")
3237

38+
3339
include(${CMAKE_FILES}/expected.cmake)
40+
include(${CMAKE_FILES}/certify.cmake)
3441

3542
# Add main SDK sources.
3643
add_subdirectory(src)

libs/common/include/config/detail/builders/http_properties_builder.hpp

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,116 @@
1010

1111
namespace launchdarkly::config::detail::builders {
1212

13+
/**
14+
* Class used for building a set of HttpProperties.
15+
* @tparam SDK The SDK type to build properties for. This affects the default
16+
* values of the built properties.
17+
*/
1318
template <typename SDK>
1419
class HttpPropertiesBuilder {
1520
public:
16-
HttpPropertiesBuilder() = default;
21+
/**
22+
* Construct a new HttpPropertiesBuilder. The builder will use the default
23+
* properties based on the SDK type. Setting a property will override
24+
* the default value.
25+
*/
26+
HttpPropertiesBuilder();
1727

28+
/**
29+
* Create a properties builder from an initial set of properties.
30+
* This can be useful when extending a set of properties for a request.
31+
* For instance to add extra headers.
32+
*
33+
* ```
34+
* HttpPropertiesBuilder(my_properties)
35+
* .Header("authorization", "my-key")
36+
* .Build();
37+
* ```
38+
*
39+
* @param properties The properties to start with.
40+
*/
41+
HttpPropertiesBuilder(built::HttpProperties properties);
42+
43+
/**
44+
* The network connection timeout.
45+
*
46+
* @param connect_timeout The connect timeout.
47+
* @return A reference to this builder.
48+
*/
1849
HttpPropertiesBuilder& ConnectTimeout(
1950
std::chrono::milliseconds connect_timeout);
2051

52+
/**
53+
* Set a read timeout. This is the time after the first byte
54+
* has been received that a read has to complete.
55+
*
56+
* @param read_timeout The read timeout.
57+
* @return A reference to this builder.
58+
*/
2159
HttpPropertiesBuilder& ReadTimeout(std::chrono::milliseconds read_timeout);
2260

61+
/**
62+
* The time for the first byte to be received during a read. If a byte
63+
* is not received within this time, then the request will be cancelled.
64+
*
65+
* @param response_timeout The response timeout.
66+
* @return A reference to this builder.
67+
*/
68+
HttpPropertiesBuilder& ResponseTimeout(
69+
std::chrono::milliseconds response_timeout);
70+
71+
/**
72+
* This should be used for wrapper SDKs to set the wrapper name.
73+
*
74+
* Wrapper information will be included in request headers.
75+
* @param wrapper_name The name of the wrapper.
76+
* @return A reference to this builder.
77+
*/
2378
HttpPropertiesBuilder& WrapperName(std::string wrapper_name);
2479

80+
/**
81+
* This should be used for wrapper SDKs to set the wrapper version.
82+
*
83+
* Wrapper information will be included in request headers.
84+
* @param wrapper_version The version of the wrapper.
85+
* @return A reference to this builder.
86+
*/
2587
HttpPropertiesBuilder& WrapperVersion(std::string wrapper_version);
2688

89+
/**
90+
* Set all custom headers. This will replace any other customer headers
91+
* that were set with the Header method, or any previously set
92+
* headers using the CustomHeaders method.
93+
* @param base_headers The custom headers.
94+
* @return A reference to this builder.
95+
*/
2796
HttpPropertiesBuilder& CustomHeaders(
2897
std::map<std::string, std::string> base_headers);
2998

99+
/**
100+
* Set a custom header value.
101+
*
102+
* Calling CustomHeaders will replace any previously set values.
103+
* @param key The key for the header.
104+
* @param value The header value.
105+
* @return A reference to this builder.
106+
*/
107+
HttpPropertiesBuilder& Header(std::string key, std::string value);
108+
109+
/**
110+
* Build a set of HttpProperties.
111+
* @return The built properties.
112+
*/
30113
[[nodiscard]] built::HttpProperties Build() const;
31114

32115
private:
33-
std::chrono::milliseconds connect_timeout_{};
34-
std::chrono::milliseconds read_timeout_{};
116+
std::chrono::milliseconds connect_timeout_;
117+
std::chrono::milliseconds read_timeout_;
118+
std::chrono::milliseconds response_timeout_;
35119
std::string wrapper_name_;
36120
std::string wrapper_version_;
37121
std::map<std::string, std::string> base_headers_;
122+
std::string user_agent_;
38123
};
39124

40125
} // namespace launchdarkly::config::detail::builders

libs/common/include/config/detail/built/http_properties.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@ class HttpProperties final {
1111
public:
1212
HttpProperties(std::chrono::milliseconds connect_timeout,
1313
std::chrono::milliseconds read_timeout,
14+
std::chrono::milliseconds response_timeout,
1415
std::string user_agent,
1516
std::map<std::string, std::string> base_headers);
1617

1718
[[nodiscard]] std::chrono::milliseconds ConnectTimeout() const;
1819
[[nodiscard]] std::chrono::milliseconds ReadTimeout() const;
20+
[[nodiscard]] std::chrono::milliseconds ResponseTimeout() const;
1921
[[nodiscard]] std::string const& UserAgent() const;
2022
[[nodiscard]] std::map<std::string, std::string> const& BaseHeaders() const;
2123

2224
private:
2325
std::chrono::milliseconds connect_timeout_;
2426
std::chrono::milliseconds read_timeout_;
27+
std::chrono::milliseconds response_timeout_;
2528
std::string user_agent_;
2629
std::map<std::string, std::string> base_headers_;
2730

libs/common/include/config/detail/defaults.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ struct Defaults<ClientSDK> {
4949
}
5050

5151
static auto HttpProperties() -> built::HttpProperties {
52-
return {std::chrono::milliseconds{10000},
53-
std::chrono::milliseconds{10000},
54-
SdkName() + "/" + SdkVersion(),
55-
std::map<std::string, std::string>()};
52+
return {
53+
std::chrono::milliseconds{10000}, std::chrono::milliseconds{10000},
54+
std::chrono::milliseconds{10000}, SdkName() + "/" + SdkVersion(),
55+
std::map<std::string, std::string>()};
5656
}
5757

5858
static auto DataSourceConfig() -> built::DataSourceConfig<ClientSDK> {
@@ -78,10 +78,10 @@ struct Defaults<ServerSDK> {
7878
}
7979

8080
static auto HttpProperties() -> built::HttpProperties {
81-
return {std::chrono::milliseconds{2000},
82-
std::chrono::milliseconds{10000},
83-
SdkName() + "/" + SdkVersion(),
84-
std::map<std::string, std::string>()};
81+
return {
82+
std::chrono::milliseconds{2000}, std::chrono::milliseconds{10000},
83+
std::chrono::milliseconds{10000}, SdkName() + "/" + SdkVersion(),
84+
std::map<std::string, std::string>()};
8585
}
8686

8787
static auto DataSourceConfig() -> built::DataSourceConfig<ServerSDK> {

0 commit comments

Comments
 (0)