Skip to content

Commit 245dd97

Browse files
authored
fix: Correctly handle a wrapper name without a wrapper version. (#499)
BEGIN_COMMIT_OVERRIDE fix: Correctly handle a wrapper name without a wrapper version. chore: Add support for the wrapper contract tests. END_COMMIT_OVERRIDE <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Properly handle wrapper name without version in HTTP headers and add wrapper config/capability to contract tests. > > - **Common HTTP properties**: > - `HttpPropertiesBuilder::Build`: Set `X-LaunchDarkly-Wrapper` to just `wrapper_name` when `wrapper_version` is empty; otherwise `name/version`. > - **Contract tests**: > - **Data model**: Add `ConfigWrapper` and optional `configuration.wrapper` in `ConfigParams`. > - **Entity managers**: Use `HttpProperties().WrapperName/WrapperVersion` when `configuration.wrapper` provided (client and server). > - **Capabilities**: Advertise `"wrapper"` in client and server test services. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 2154d6e. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent cf8e429 commit 245dd97

File tree

6 files changed

+36
-3
lines changed

6 files changed

+36
-3
lines changed

contract-tests/client-contract-tests/src/entity_manager.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ std::optional<std::string> EntityManager::create(ConfigParams const& in) {
146146
config_builder.HttpProperties().Tls(std::move(builder));
147147
}
148148

149+
if (in.wrapper) {
150+
if (!in.wrapper->name.empty()) {
151+
config_builder.HttpProperties().WrapperName(in.wrapper->name);
152+
}
153+
if (!in.wrapper->version.empty()) {
154+
config_builder.HttpProperties().WrapperVersion(in.wrapper->version);
155+
}
156+
}
157+
149158
auto config = config_builder.Build();
150159
if (!config) {
151160
LD_LOG(logger_, LogLevel::kWarn)

contract-tests/client-contract-tests/src/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ int main(int argc, char* argv[]) {
4747
srv.add_capability("tls:skip-verify-peer");
4848
srv.add_capability("tls:custom-ca");
4949
srv.add_capability("client-prereq-events");
50+
srv.add_capability("wrapper");
5051
// Proxies are supported only with CURL networking.
5152
#ifdef LD_CURL_NETWORKING
5253
srv.add_capability("http-proxy");

contract-tests/data-model/include/data_model/data_model.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ struct ConfigHooksParams {
143143

144144
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ConfigHooksParams, hooks);
145145

146+
struct ConfigWrapper {
147+
std::string name;
148+
std::string version;
149+
};
150+
151+
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ConfigWrapper, name, version);
152+
146153
struct ConfigParams {
147154
std::string credential;
148155
std::optional<uint32_t> startWaitTimeMs;
@@ -156,6 +163,7 @@ struct ConfigParams {
156163
std::optional<ConfigTLSParams> tls;
157164
std::optional<ConfigProxyParams> proxy;
158165
std::optional<ConfigHooksParams> hooks;
166+
std::optional<ConfigWrapper> wrapper;
159167
};
160168

161169
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ConfigParams,
@@ -170,7 +178,8 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ConfigParams,
170178
tags,
171179
tls,
172180
proxy,
173-
hooks);
181+
hooks,
182+
wrapper);
174183

175184
struct ContextSingleParams {
176185
std::optional<std::string> kind;

contract-tests/server-contract-tests/src/entity_manager.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ std::optional<std::string> EntityManager::create(ConfigParams const& in) {
145145
}
146146
}
147147

148+
if (in.wrapper) {
149+
if (!in.wrapper->name.empty()) {
150+
config_builder.HttpProperties().WrapperName(in.wrapper->name);
151+
}
152+
if (!in.wrapper->version.empty()) {
153+
config_builder.HttpProperties().WrapperVersion(in.wrapper->version);
154+
}
155+
}
156+
148157
auto config = config_builder.Build();
149158
if (!config) {
150159
LD_LOG(logger_, LogLevel::kWarn)

contract-tests/server-contract-tests/src/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ int main(int argc, char* argv[]) {
5050
srv.add_capability("client-prereq-events");
5151
srv.add_capability("evaluation-hooks");
5252
srv.add_capability("track-hooks");
53+
srv.add_capability("wrapper");
5354

5455
net::signal_set signals{ioc, SIGINT, SIGTERM};
5556

libs/common/src/config/http_properties_builder.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,12 @@ template <typename SDK>
133133
built::HttpProperties HttpPropertiesBuilder<SDK>::Build() const {
134134
if (!wrapper_name_.empty()) {
135135
std::map<std::string, std::string> headers_with_wrapper(base_headers_);
136-
headers_with_wrapper["X-LaunchDarkly-Wrapper"] =
137-
wrapper_name_ + "/" + wrapper_version_;
136+
if (wrapper_version_.empty()) {
137+
headers_with_wrapper["X-LaunchDarkly-Wrapper"] = wrapper_name_;
138+
} else {
139+
headers_with_wrapper["X-LaunchDarkly-Wrapper"] =
140+
wrapper_name_ + "/" + wrapper_version_;
141+
}
138142
return {connect_timeout_, read_timeout_, write_timeout_,
139143
response_timeout_, headers_with_wrapper, tls_.Build(), proxy_};
140144
}

0 commit comments

Comments
 (0)