Skip to content

Commit e6d8314

Browse files
authored
fix: include query parameters on streaming requests (#97)
I was using the wrong api on `boost::url` - the `path()` doesn't include query parameters (important for `withReason`!). It's also not encoded, so wrong on two accounts. Switched to `encoded_target()`.
1 parent d2852e7 commit e6d8314

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

apps/sdk-contract-tests/test-suppressions.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
events/summary events/basic counter behavior
22
events/summary events/reset after each flush
3-
streaming/requests/query parameters/evaluationReasons set to true/GET
4-
streaming/requests/query parameters/evaluationReasons set to true/REPORT
53
tags/disallowed characters
64

75
# The Client doesn't need to know how to deserialize users.

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ class FoxyClient : public Client,
5858
read_timeout_(read_timeout),
5959
write_timeout_(write_timeout),
6060
req_(std::move(req)),
61-
body_parser_(),
62-
session_(executor,
61+
session_(std::move(executor),
6362
foxy::session_opts{ToOptRef(ssl_context_),
6463
connect_timeout.value_or(kNoTimeout)}),
6564
logger_(std::move(logger)) {
@@ -69,7 +68,7 @@ class FoxyClient : public Client,
6968
body_parser_.get().body().on_event(std::move(receiver));
7069
}
7170

72-
void fail(boost::system::error_code ec, std::string what) {
71+
void fail(boost::system::error_code ec, std::string const& what) {
7372
logger_("sse-client: " + what + ": " + ec.message());
7473
async_shutdown(nullptr);
7574
}
@@ -83,12 +82,11 @@ class FoxyClient : public Client,
8382

8483
void async_shutdown(std::function<void()> completion) override {
8584
session_.async_shutdown(beast::bind_front_handler(
86-
&FoxyClient::on_shutdown, shared_from_this(),
87-
std::move(completion)));
85+
&FoxyClient::on_shutdown, std::move(completion)));
8886
}
8987

90-
void on_shutdown(std::function<void()> completion,
91-
boost::system::error_code ec) {
88+
static void on_shutdown(std::function<void()> completion,
89+
boost::system::error_code ec) {
9290
boost::ignore_unused(ec);
9391
if (completion) {
9492
completion();
@@ -229,15 +227,15 @@ std::shared_ptr<Client> Builder::build() {
229227

230228
auto request = request_;
231229

232-
// Don't send a body unless the method is POST or REPORT
233-
if (!(request.method() == http::verb::post ||
234-
request.method() == http::verb::report)) {
230+
// If this isn't a post or report, ensure the body is empty.
231+
if (request.method() != http::verb::post &&
232+
request.method() != http::verb::report) {
235233
request.body() = "";
236234
} else {
237235
// If it is, then setup Content-Type, only if one wasn't
238236
// specified.
239-
if (auto it = request.find(http::field::content_type);
240-
it == request.end()) {
237+
if (auto content_header = request.find(http::field::content_type);
238+
content_header == request.end()) {
241239
request.set(http::field::content_type, "text/plain");
242240
}
243241
}
@@ -247,7 +245,7 @@ std::shared_ptr<Client> Builder::build() {
247245
std::string host = uri_components->host();
248246

249247
request.set(http::field::host, host);
250-
request.target(uri_components->path());
248+
request.target(uri_components->encoded_target());
251249

252250
std::string service = uri_components->has_port() ? uri_components->port()
253251
: uri_components->scheme();

0 commit comments

Comments
 (0)