Skip to content

Commit

Permalink
only enable for client side SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
cwaldren-ld committed Nov 12, 2024
1 parent d04337c commit ba28a84
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@
#include <vector>

#include <launchdarkly/config/shared/built/http_properties.hpp>
#include <launchdarkly/config/shared/sdks.hpp>

namespace launchdarkly::config::shared::builders {

// namespace detail {
// template <typename T>
// struct is_client_sdk : std::false_type {};
//
// template <>
// struct is_client_sdk<config::shared::ClientSDK> : std::true_type {};
// } // namespace detail

/**
* Class used for building TLS options used within HttpProperties.
* @tparam SDK The SDK type to build options for. This affects the default
Expand Down Expand Up @@ -179,7 +188,10 @@ class HttpPropertiesBuilder {
HttpPropertiesBuilder& Tls(TlsBuilder<SDK> builder);

/**
* Specifies an HTTP proxy which the client should use to communicate
* NOTE: This method and the associated 'http_proxy' environment variable
* are only available for the client-side SDK.
*
* Specifies an HTTP proxy which the SDK should use to communicate
* with LaunchDarkly.
*
* SDK <-- HTTP, plaintext --> Proxy <-- HTTPS --> LaunchDarkly
Expand All @@ -195,6 +207,9 @@ class HttpPropertiesBuilder {
*
* @param http_proxy HTTP proxy URL.
*/
template <
typename T = SDK,
std::enable_if_t<std::is_same_v<T, config::shared::ClientSDK>, int> = 0>
HttpPropertiesBuilder& HttpProxy(std::string http_proxy);

[[nodiscard]] built::HttpProperties Build() const;
Expand Down
19 changes: 10 additions & 9 deletions libs/common/src/config/http_properties_builder.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#include <launchdarkly/config/shared/builders/http_properties_builder.hpp>
#include <launchdarkly/config/shared/defaults.hpp>
#include <launchdarkly/config/shared/sdks.hpp>

#include <cstring>
#include <utility>

namespace launchdarkly::config::shared::builders {

Expand Down Expand Up @@ -124,6 +122,7 @@ HttpPropertiesBuilder<SDK>& HttpPropertiesBuilder<SDK>::Tls(
}

template <typename SDK>
template <typename T, std::enable_if_t<std::is_same_v<T, ClientSDK>, int>>
HttpPropertiesBuilder<SDK>& HttpPropertiesBuilder<SDK>::HttpProxy(
std::string http_proxy) {
http_proxy_ = std::move(http_proxy);
Expand All @@ -148,13 +147,15 @@ built::HttpProperties HttpPropertiesBuilder<SDK>::Build() const {
wrapper_name_ + "/" + wrapper_version_;
}

return {connect_timeout_,
read_timeout_,
write_timeout_,
response_timeout_,
std::move(headers),
tls_.Build(),
http_proxy_.has_value() ? http_proxy_ : HttpProxyFromEnv()};
std::optional<std::string> http_proxy;

if constexpr (std::is_same_v<SDK, ClientSDK>) {
http_proxy = http_proxy_.has_value() ? http_proxy_ : HttpProxyFromEnv();
}

return {connect_timeout_, read_timeout_, write_timeout_,
response_timeout_, std::move(headers), tls_.Build(),
http_proxy};
}

template class TlsBuilder<config::shared::ClientSDK>;
Expand Down

0 comments on commit ba28a84

Please sign in to comment.