Skip to content

Commit 729da73

Browse files
committed
fix: drop trailing empty segment before appending FDv2 path
1 parent 716b270 commit 729da73

3 files changed

Lines changed: 30 additions & 8 deletions

File tree

libs/server-sdk/src/data_systems/fdv2/fdv2_polling_impl.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,14 @@ network::HttpRequest MakeFDv2PollRequest(
5454
}
5555

5656
boost::urls::url u = parsed.value();
57-
// Use segments to join the path; string concatenation would produce a
58-
// double slash when the base URL ends in '/'.
59-
u.segments().push_back("sdk");
60-
u.segments().push_back("poll");
57+
// A trailing '/' on the base URL appears as an empty final segment;
58+
// remove it so subsequent push_backs don't produce a double slash.
59+
auto segs = u.segments();
60+
if (!segs.empty() && segs.back().empty()) {
61+
segs.pop_back();
62+
}
63+
segs.push_back("sdk");
64+
segs.push_back("poll");
6165
if (selector.value) {
6266
u.params().append({"basis", selector.value->state});
6367
}

libs/server-sdk/src/data_systems/fdv2/streaming_synchronizer.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,14 @@ void FDv2StreamingSynchronizer::State::EnsureStarted(
7575

7676
boost::urls::url u = parsed.value();
7777

78-
// Safer way of appending /sdk/stream than string concatenation: avoids
79-
// double slashes if the base URL has a trailing slash.
80-
u.segments().push_back("sdk");
81-
u.segments().push_back("stream");
78+
// A trailing '/' on the base URL appears as an empty final segment;
79+
// remove it so subsequent push_backs don't produce a double slash.
80+
auto segs = u.segments();
81+
if (!segs.empty() && segs.back().empty()) {
82+
segs.pop_back();
83+
}
84+
segs.push_back("sdk");
85+
segs.push_back("stream");
8286

8387
// basis and filter are not added here — they are appended per-connect by
8488
// the on_connect hook (OnConnect), so that each (re)connection uses the
@@ -184,6 +188,10 @@ void FDv2StreamingSynchronizer::State::OnResponse(
184188
}
185189

186190
void FDv2StreamingSynchronizer::State::OnEvent(sse::Event const& event) {
191+
if (!FDv2ProtocolHandler::IsKnownEvent(event.type())) {
192+
return;
193+
}
194+
187195
boost::system::error_code ec;
188196
auto data = boost::json::parse(event.data(), ec);
189197
if (ec) {

libs/server-sdk/tests/fdv2_polling_impl_test.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ TEST(MakeFDv2PollRequestTest, BaseWithTrailingSlashDoesNotProduceDoubleSlash) {
119119
EXPECT_EQ(req.Url(), "http://example.com/sdk/poll");
120120
}
121121

122+
TEST(MakeFDv2PollRequestTest, BaseWithSubpathTrailingSlashJoinsCleanly) {
123+
config::shared::built::ServiceEndpoints endpoints{
124+
"http://example.com/relay/", "", ""};
125+
auto props =
126+
config::shared::Defaults<config::shared::ServerSDK>::HttpProperties();
127+
auto req = MakeFDv2PollRequest(endpoints, props, data_model::Selector{},
128+
std::nullopt);
129+
EXPECT_EQ(req.Url(), "http://example.com/relay/sdk/poll");
130+
}
131+
122132
TEST(MakeFDv2PollRequestTest, ValidFilterKeyIsIncluded) {
123133
config::shared::built::ServiceEndpoints endpoints{"http://example.com", "",
124134
""};

0 commit comments

Comments
 (0)