diff --git a/contract-tests/client-contract-tests/src/entity_manager.cpp b/contract-tests/client-contract-tests/src/entity_manager.cpp index ac1d2587b..493f2789f 100644 --- a/contract-tests/client-contract-tests/src/entity_manager.cpp +++ b/contract-tests/client-contract-tests/src/entity_manager.cpp @@ -40,7 +40,9 @@ std::optional EntityManager::create(ConfigParams const& in) { if (in.proxy) { if (in.proxy->httpProxy) { - config_builder.HttpProperties().HttpProxy(*in.proxy->httpProxy); + config_builder.HttpProperties().Proxy( + HttpPropertiesBuilder::ProxyBuilder().HttpProxy( + *in.proxy->httpProxy)); } } diff --git a/libs/client-sdk/include/launchdarkly/client_side/bindings/c/config/builder.h b/libs/client-sdk/include/launchdarkly/client_side/bindings/c/config/builder.h index dc91f9487..501adf95d 100644 --- a/libs/client-sdk/include/launchdarkly/client_side/bindings/c/config/builder.h +++ b/libs/client-sdk/include/launchdarkly/client_side/bindings/c/config/builder.h @@ -425,7 +425,7 @@ LDClientConfigBuilder_HttpProperties_Header(LDClientConfigBuilder b, char const* value); /** - * Creates a new proxy options builder for the HttpProperties builder. + * Creates a new ProxyBuilder for the HttpProperties builder. * * If not passed into the HttpProperties * builder, must be manually freed with LDClientHttpPropertiesProxyBuilder_Free. @@ -436,7 +436,7 @@ LD_EXPORT(LDClientHttpPropertiesProxyBuilder) LDClientHttpPropertiesProxyBuilder_New(void); /** - * Frees a proxy options builder. Do not call if the builder was consumed by + * Frees a ProxyBuilder. Do not call if the builder was consumed by * the HttpProperties builder. * * @param b Builder to free. @@ -445,10 +445,7 @@ LD_EXPORT(void) LDClientHttpPropertiesProxyBuilder_Free(LDClientHttpPropertiesProxyBuilder b); /** - * Specifies an HTTP proxy which the client should use to communicate - * with LaunchDarkly. - * - * SDK <-- HTTP, plaintext --> Proxy <-- HTTPS --> LaunchDarkly + * Specifies an HTTP proxy which the client should use for any HTTP requests. * * This setting affects streaming mode, polling mode, and event delivery. * The argument should be of the form: 'http://proxy.example.com:8080'. @@ -462,12 +459,29 @@ LDClientHttpPropertiesProxyBuilder_Free(LDClientHttpPropertiesProxyBuilder b); * @param b Client config builder. Must not be NULL. * @param http_proxy HTTP proxy URL. Must not be NULL. */ + LD_EXPORT(void) -LDClientConfigBuilder_HttpProperties_HttpProxy(LDClientConfigBuilder b, - char const* http_proxy); +LDClientHttpPropertiesProxyBuilder_HttpProxy( + LDClientHttpPropertiesProxyBuilder b, + char const* http_proxy); + +/** + * Sets the ProxyBuilder. The builder is automatically freed. + * + * WARNING: Do not call any other LDClientHttpPropertiesProxyBuilder function on + * the provided LDClientHttpPropertiesProxyBuilder after calling this function. + * It is undefined behavior. + * + * @param b Client config builder. Must not be NULL. + * @param proxy_builder The ProxyBuilder. Must not be NULL. + */ +LD_EXPORT(void) +LDClientConfigBuilder_HttpProperties_Proxy( + LDClientConfigBuilder b, + LDClientHttpPropertiesProxyBuilder proxy_builder); /** - * Sets the TLS options builder. The builder is automatically freed. + * Sets the TlsBuilder. The builder is automatically freed. * * WARNING: Do not call any other * LDClientHttpPropertiesTlsBuilder function on the provided @@ -475,7 +489,7 @@ LDClientConfigBuilder_HttpProperties_HttpProxy(LDClientConfigBuilder b, * It is undefined behavior. * * @param b Client config builder. Must not be NULL. - * @param tls_builder The TLS options builder. Must not be NULL. + * @param tls_builder The TlsBuilder. Must not be NULL. */ LD_EXPORT(void) LDClientConfigBuilder_HttpProperties_Tls( diff --git a/libs/client-sdk/src/bindings/c/builder.cpp b/libs/client-sdk/src/bindings/c/builder.cpp index 019a1b14d..b7d589a09 100644 --- a/libs/client-sdk/src/bindings/c/builder.cpp +++ b/libs/client-sdk/src/bindings/c/builder.cpp @@ -329,7 +329,7 @@ LDClientHttpPropertiesProxyBuilder_Free(LDClientHttpPropertiesProxyBuilder b) { } LD_EXPORT(void) -LDClientConfigBuilder_HttpProperties_HttpProxy( +LDClientConfigBuilder_HttpProperties_Proxy( LDClientConfigBuilder b, LDClientHttpPropertiesProxyBuilder proxy_builder) { LD_ASSERT_NOT_NULL(b); @@ -340,6 +340,16 @@ LDClientConfigBuilder_HttpProperties_HttpProxy( LDClientHttpPropertiesProxyBuilder_Free(proxy_builder); } +LD_EXPORT(void) +LDClientHttpPropertiesProxyBuilder_HttpProxy( + LDClientHttpPropertiesProxyBuilder b, + char const* http_proxy) { + LD_ASSERT_NOT_NULL(b); + LD_ASSERT_NOT_NULL(http_proxy); + + TO_PROXY_BUILDER(b)->HttpProxy(http_proxy); +} + LD_EXPORT(void) LDClientConfigBuilder_HttpProperties_Tls( LDClientConfigBuilder b, diff --git a/libs/client-sdk/tests/client_config_test.cpp b/libs/client-sdk/tests/client_config_test.cpp index df94f48d8..14809a8a5 100644 --- a/libs/client-sdk/tests/client_config_test.cpp +++ b/libs/client-sdk/tests/client_config_test.cpp @@ -263,3 +263,28 @@ TEST(ClientConfigBindings, CustomLogger) { ASSERT_EQ(args.write->level, LD_LOG_ERROR); ASSERT_EQ(args.write->msg, "hello"); } + +TEST(ClientConfigBindings, ProxyOptions) { + using namespace launchdarkly; + + LDClientConfigBuilder builder = LDClientConfigBuilder_New("sdk-123"); + + LDClientHttpPropertiesProxyBuilder proxy_builder = + LDClientHttpPropertiesProxyBuilder_New(); + + LDClientHttpPropertiesProxyBuilder_HttpProxy(proxy_builder, + "http://proxy.com:8080"); + + LDClientConfigBuilder_HttpProperties_Proxy(builder, proxy_builder); + + LDClientConfig config = nullptr; + LDStatus status = LDClientConfigBuilder_Build(builder, &config); + ASSERT_TRUE(LDStatus_Ok(status)); + + auto client_config = reinterpret_cast(config); + + ASSERT_EQ(client_config->HttpProperties().Proxy().HttpProxy(), + "http://proxy.com:8080"); + + LDClientConfig_Free(config); +}