Skip to content

Commit f0114e3

Browse files
authored
fix: handle service endpoints with custom ports correctly (#389)
Users can configure the SDK with custom service endpoints. There was a bug in the endpoint configuration process where using a custom port would mean you couldn't also specify a HTTPS connection. That is, if you specified something like `https://localhost:9090` for testing, it would see `9090` and not setup the proper SSL context needed. This had no affect on default usage of the SDK, because the default LaunchDarkly endpoints don't specify a port.
1 parent a5028cb commit f0114e3

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

libs/internal/include/launchdarkly/network/asio_requester.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ class AsioRequester {
323323
request->Port().value_or(request->Https() ? "https" : "http");
324324

325325
std::shared_ptr<ssl::context> ssl;
326-
if (service == "https") {
326+
if (request->Https()) {
327327
ssl = this->ssl_ctx_;
328328
}
329329

libs/server-sent-events/src/client.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,11 +589,22 @@ std::shared_ptr<Client> Builder::build() {
589589
request.set(http::field::host, host);
590590
request.target(uri_components->encoded_target());
591591

592+
if (uri_components->has_scheme()) {
593+
if (!(uri_components->scheme_id() == boost::urls::scheme::http ||
594+
uri_components->scheme_id() == boost::urls::scheme::https)) {
595+
return nullptr;
596+
}
597+
}
598+
599+
// The resolver accepts either a port number or a service name. If the
600+
// URL specifies a port, use that - otherwise, pass in the scheme as the
601+
// service name (which will be either http or https due to the check
602+
// above.)
592603
std::string service = uri_components->has_port() ? uri_components->port()
593604
: uri_components->scheme();
594605

595606
std::optional<ssl::context> ssl;
596-
if (service == "https") {
607+
if (uri_components->scheme_id() == boost::urls::scheme::https) {
597608
ssl = launchdarkly::foxy::make_ssl_ctx(ssl::context::tlsv12_client);
598609
ssl->set_default_verify_paths();
599610
}

0 commit comments

Comments
 (0)