Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions libs/client-sdk/src/client_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ using launchdarkly::config::shared::built::HttpProperties;

static std::shared_ptr<IDataSource> MakeDataSource(
HttpProperties const& http_properties,
std::optional<std::string> app_tags,
Config const& config,
Context const& context,
boost::asio::any_io_executor const& executor,
Expand All @@ -48,11 +47,6 @@ static std::shared_ptr<IDataSource> MakeDataSource(

auto builder = HttpPropertiesBuilder(http_properties);

// Event sources should include application tags.
if (app_tags) {
builder.Header("x-launchdarkly-tags", *app_tags);
}

auto data_source_properties = builder.Build();

if (config.DataSourceConfig().method.index() == 0) {
Expand Down Expand Up @@ -93,10 +87,12 @@ ClientImpl::ClientImpl(Config config,
Context context,
std::string const& version)
: config_(config),
http_properties_(HttpPropertiesBuilder(config.HttpProperties())
.Header("user-agent", "CPPClient/" + version)
.Header("authorization", config.SdkKey())
.Build()),
http_properties_(
HttpPropertiesBuilder(config.HttpProperties())
.Header("user-agent", "CPPClient/" + version)
.Header("authorization", config.SdkKey())
.Header("x-launchdarkly-tags", config.ApplicationTag())
.Build()),
logger_(MakeLogger(config.Logging())),
ioc_(kAsioConcurrencyHint),
work_(boost::asio::make_work_guard(ioc_)),
Expand All @@ -106,10 +102,9 @@ ClientImpl::ClientImpl(Config config,
config.Persistence().max_contexts_,
MakePersistence(config)),
data_source_factory_([this]() {
return MakeDataSource(http_properties_, config_.ApplicationTag(),
config_, context_, ioc_.get_executor(),
flag_manager_.Updater(), status_manager_,
logger_);
return MakeDataSource(http_properties_, config_, context_,
ioc_.get_executor(), flag_manager_.Updater(),
status_manager_, logger_);
}),
data_source_(nullptr),
event_processor_(nullptr),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <chrono>
#include <map>
#include <optional>
#include <string>
#include <vector>

Expand Down Expand Up @@ -106,14 +107,14 @@ class HttpPropertiesBuilder {
std::map<std::string, std::string> base_headers);

/**
* Set a custom header value.
*
* Calling Headers will replace any previously set values.
* @param key The key for the header.
* @param value The header value.
* Set an optional header value. If the value is std::nullopt, any existing
* header by that name is removed.
* @param name The name of the header.
* @param value The optional header value.
* @return A reference to this builder.
*/
HttpPropertiesBuilder& Header(std::string key, std::string value);
HttpPropertiesBuilder& Header(std::string key,
std::optional<std::string> value);

/**
* Build a set of HttpProperties.
Expand Down
8 changes: 6 additions & 2 deletions libs/common/src/config/http_properties_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ HttpPropertiesBuilder<SDK>& HttpPropertiesBuilder<SDK>::Headers(
template <typename SDK>
HttpPropertiesBuilder<SDK>& HttpPropertiesBuilder<SDK>::Header(
std::string key,
std::string value) {
base_headers_.insert_or_assign(key, value);
std::optional<std::string> value) {
if (value) {
base_headers_.insert_or_assign(key, *value);
} else {
base_headers_.erase(key);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also have this just be a no-op if it's nullopt, but this also allows for removal without needing another API.

return *this;
}

Expand Down