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 81c5cb64c..cc8a7c9ba 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 @@ -421,6 +421,28 @@ LDClientConfigBuilder_HttpProperties_Header(LDClientConfigBuilder b, char const* key, char const* value); +/** + * Specifies an HTTP proxy which the client should use to communicate + * with LaunchDarkly. + * + * SDK <-- HTTP, plaintext --> Proxy <-- HTTPS --> LaunchDarkly + * + * This setting affects streaming mode, polling mode, and event delivery. + * The argument should be of the form: 'http://proxy.example.com:8080'. + * + * The scheme must be 'http' and the port is optional (80 if not + * specified.) + * + * The SDK respects the 'http_proxy' environment variable as an alternative + * to this method. If both are set, this method takes precedence. + * + * @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); + /** * Sets the TLS options builder. The builder is automatically freed. * diff --git a/libs/client-sdk/src/bindings/c/builder.cpp b/libs/client-sdk/src/bindings/c/builder.cpp index 7994207e4..6de3bb647 100644 --- a/libs/client-sdk/src/bindings/c/builder.cpp +++ b/libs/client-sdk/src/bindings/c/builder.cpp @@ -311,6 +311,15 @@ LDClientConfigBuilder_HttpProperties_Header(LDClientConfigBuilder b, TO_BUILDER(b)->HttpProperties().Header(key, value); } +LD_EXPORT(void) +LDClientConfigBuilder_HttpProperties_HttpProxy(LDClientConfigBuilder b, + char const* http_proxy) { + LD_ASSERT_NOT_NULL(b); + LD_ASSERT_NOT_NULL(http_proxy); + + TO_BUILDER(b)->HttpProperties().HttpProxy(http_proxy); +} + LD_EXPORT(void) LDClientConfigBuilder_HttpProperties_Tls( LDClientConfigBuilder b, diff --git a/libs/common/include/launchdarkly/config/shared/builders/http_properties_builder.hpp b/libs/common/include/launchdarkly/config/shared/builders/http_properties_builder.hpp index 2f2de60ec..ffe1a5f3e 100644 --- a/libs/common/include/launchdarkly/config/shared/builders/http_properties_builder.hpp +++ b/libs/common/include/launchdarkly/config/shared/builders/http_properties_builder.hpp @@ -179,16 +179,24 @@ class HttpPropertiesBuilder { HttpPropertiesBuilder& Tls(TlsBuilder builder); /** - * Sets an HTTP proxy URL. - * @param http_proxy The proxy, for example 'http://proxy.example.com:8080'. - * @return A reference to this builder. + * Specifies an HTTP proxy which the client should use to communicate + * with LaunchDarkly. + * + * SDK <-- HTTP, plaintext --> Proxy <-- HTTPS --> LaunchDarkly + * + * This setting affects streaming mode, polling mode, and event delivery. + * The argument should be of the form: 'http://proxy.example.com:8080'. + * + * The scheme must be 'http' and the port is optional (80 if not + * specified.) + * + * The SDK respects the 'http_proxy' environment variable as an alternative + * to this method. If both are set, this method takes precedence. + * + * @param http_proxy HTTP proxy URL. */ HttpPropertiesBuilder& HttpProxy(std::string http_proxy); - /** - * Build a set of HttpProperties. - * @return The built properties. - */ [[nodiscard]] built::HttpProperties Build() const; private: diff --git a/libs/common/src/config/http_properties_builder.cpp b/libs/common/src/config/http_properties_builder.cpp index 8fa08b8c4..3ddfb6651 100644 --- a/libs/common/src/config/http_properties_builder.cpp +++ b/libs/common/src/config/http_properties_builder.cpp @@ -153,7 +153,7 @@ built::HttpProperties HttpPropertiesBuilder::Build() const { response_timeout_, std::move(headers), tls_.Build(), - http_proxy_ ? *http_proxy_ : HttpProxyFromEnv()}; + http_proxy_.has_value() ? http_proxy_ : HttpProxyFromEnv()}; } template class TlsBuilder; diff --git a/libs/server-sdk/src/data_systems/background_sync/sources/streaming/streaming_data_source.cpp b/libs/server-sdk/src/data_systems/background_sync/sources/streaming/streaming_data_source.cpp index f831b34d9..778eef153 100644 --- a/libs/server-sdk/src/data_systems/background_sync/sources/streaming/streaming_data_source.cpp +++ b/libs/server-sdk/src/data_systems/background_sync/sources/streaming/streaming_data_source.cpp @@ -119,10 +119,6 @@ void StreamingDataSource::StartAsync( client_builder.custom_ca_file(*ca_file); } - if (http_config_.HttpProxy()) { - client_builder.http_proxy(*http_config_.HttpProxy()); - } - auto weak_self = weak_from_this(); client_builder.receiver([weak_self](launchdarkly::sse::Event const& event) { diff --git a/libs/server-sent-events/src/client.cpp b/libs/server-sent-events/src/client.cpp index 91353f623..cd39354b0 100644 --- a/libs/server-sent-events/src/client.cpp +++ b/libs/server-sent-events/src/client.cpp @@ -660,13 +660,6 @@ std::shared_ptr Builder::build() { return nullptr; } - // Although a proxy might talk HTTP on port 443, that would be - // very weird and is likely a misconfiguration. - if (http_proxy_components->has_port() && - http_proxy_components->port() == "443") { - return nullptr; - } - tcp_host = http_proxy_components->host(); // If they didn't specify a port, then the uri is of the form