Skip to content

Commit c8b3aee

Browse files
authored
fix: ensure x-launchdarkly-tags is sent in event requests (#145)
Moves application tag into HTTP Config, so it can propagate to data sources + event sender.
1 parent 2d60197 commit c8b3aee

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

libs/client-sdk/src/client_impl.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ using launchdarkly::config::shared::built::HttpProperties;
3434

3535
static std::shared_ptr<IDataSource> MakeDataSource(
3636
HttpProperties const& http_properties,
37-
std::optional<std::string> app_tags,
3837
Config const& config,
3938
Context const& context,
4039
boost::asio::any_io_executor const& executor,
@@ -48,11 +47,6 @@ static std::shared_ptr<IDataSource> MakeDataSource(
4847

4948
auto builder = HttpPropertiesBuilder(http_properties);
5049

51-
// Event sources should include application tags.
52-
if (app_tags) {
53-
builder.Header("x-launchdarkly-tags", *app_tags);
54-
}
55-
5650
auto data_source_properties = builder.Build();
5751

5852
if (config.DataSourceConfig().method.index() == 0) {
@@ -93,10 +87,12 @@ ClientImpl::ClientImpl(Config config,
9387
Context context,
9488
std::string const& version)
9589
: config_(config),
96-
http_properties_(HttpPropertiesBuilder(config.HttpProperties())
97-
.Header("user-agent", "CPPClient/" + version)
98-
.Header("authorization", config.SdkKey())
99-
.Build()),
90+
http_properties_(
91+
HttpPropertiesBuilder(config.HttpProperties())
92+
.Header("user-agent", "CPPClient/" + version)
93+
.Header("authorization", config.SdkKey())
94+
.Header("x-launchdarkly-tags", config.ApplicationTag())
95+
.Build()),
10096
logger_(MakeLogger(config.Logging())),
10197
ioc_(kAsioConcurrencyHint),
10298
work_(boost::asio::make_work_guard(ioc_)),
@@ -106,10 +102,9 @@ ClientImpl::ClientImpl(Config config,
106102
config.Persistence().max_contexts_,
107103
MakePersistence(config)),
108104
data_source_factory_([this]() {
109-
return MakeDataSource(http_properties_, config_.ApplicationTag(),
110-
config_, context_, ioc_.get_executor(),
111-
flag_manager_.Updater(), status_manager_,
112-
logger_);
105+
return MakeDataSource(http_properties_, config_, context_,
106+
ioc_.get_executor(), flag_manager_.Updater(),
107+
status_manager_, logger_);
113108
}),
114109
data_source_(nullptr),
115110
event_processor_(nullptr),

libs/common/include/launchdarkly/config/shared/builders/http_properties_builder.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <chrono>
44
#include <map>
5+
#include <optional>
56
#include <string>
67
#include <vector>
78

@@ -106,14 +107,14 @@ class HttpPropertiesBuilder {
106107
std::map<std::string, std::string> base_headers);
107108

108109
/**
109-
* Set a custom header value.
110-
*
111-
* Calling Headers will replace any previously set values.
112-
* @param key The key for the header.
113-
* @param value The header value.
110+
* Set an optional header value. If the value is std::nullopt, any existing
111+
* header by that name is removed.
112+
* @param name The name of the header.
113+
* @param value The optional header value.
114114
* @return A reference to this builder.
115115
*/
116-
HttpPropertiesBuilder& Header(std::string key, std::string value);
116+
HttpPropertiesBuilder& Header(std::string key,
117+
std::optional<std::string> value);
117118

118119
/**
119120
* Build a set of HttpProperties.

libs/common/src/config/http_properties_builder.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ HttpPropertiesBuilder<SDK>& HttpPropertiesBuilder<SDK>::Headers(
7272
template <typename SDK>
7373
HttpPropertiesBuilder<SDK>& HttpPropertiesBuilder<SDK>::Header(
7474
std::string key,
75-
std::string value) {
76-
base_headers_.insert_or_assign(key, value);
75+
std::optional<std::string> value) {
76+
if (value) {
77+
base_headers_.insert_or_assign(key, *value);
78+
} else {
79+
base_headers_.erase(key);
80+
}
7781
return *this;
7882
}
7983

0 commit comments

Comments
 (0)