fix(websockets): add query to URL (#6141)

Reviewed-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
nerix
2025-11-02 16:07:58 +01:00
committed by GitHub
parent e4a4d812e3
commit 072bc897a0
7 changed files with 22 additions and 10 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ on:
- main - main
env: env:
TWITCH_PUBSUB_SERVER_TAG: v1.0.11 TWITCH_PUBSUB_SERVER_TAG: v1.0.12
HTTPBOX_TAG: v0.2.1 HTTPBOX_TAG: v0.2.1
QT_QPA_PLATFORM: minimal QT_QPA_PLATFORM: minimal
+1 -1
View File
@@ -7,7 +7,7 @@ on:
merge_group: merge_group:
env: env:
TWITCH_PUBSUB_SERVER_TAG: v1.0.11 TWITCH_PUBSUB_SERVER_TAG: v1.0.12
HTTPBOX_TAG: v0.2.1 HTTPBOX_TAG: v0.2.1
QT_QPA_PLATFORM: minimal QT_QPA_PLATFORM: minimal
HOMEBREW_NO_AUTO_UPDATE: 1 HOMEBREW_NO_AUTO_UPDATE: 1
+1 -1
View File
@@ -7,7 +7,7 @@ on:
merge_group: merge_group:
env: env:
TWITCH_PUBSUB_SERVER_TAG: v1.0.11 TWITCH_PUBSUB_SERVER_TAG: v1.0.12
HTTPBOX_TAG: v0.2.1 HTTPBOX_TAG: v0.2.1
QT_QPA_PLATFORM: minimal QT_QPA_PLATFORM: minimal
CONAN_VERSION: 2.11.0 CONAN_VERSION: 2.11.0
+1 -1
View File
@@ -11,7 +11,7 @@ on:
- main - main
env: env:
TWITCH_PUBSUB_SERVER_TAG: v1.0.11 TWITCH_PUBSUB_SERVER_TAG: v1.0.12
HTTPBOX_TAG: v0.2.1 HTTPBOX_TAG: v0.2.1
QT_QPA_PLATFORM: minimal QT_QPA_PLATFORM: minimal
+1
View File
@@ -15,6 +15,7 @@
- Bugfix: Fixed settings occasionally not opening when clicking on "Manage Accounts" in the account switcher. (#6543) - Bugfix: Fixed settings occasionally not opening when clicking on "Manage Accounts" in the account switcher. (#6543)
- Bugfix: Fixed font change not resulting in forced layout update. (#6536) - Bugfix: Fixed font change not resulting in forced layout update. (#6536)
- Bugfix: Fixed scrollbar rect computation potentially resulting in overflows. (#6547) - Bugfix: Fixed scrollbar rect computation potentially resulting in overflows. (#6547)
- Bugfix: Forward query params to websocket URLs. (#6141)
- Dev: Update release documentation. (#6498) - Dev: Update release documentation. (#6498)
- Dev: Make code sanitizers opt in with the `CHATTERINO_SANITIZER_SUPPORT` CMake option. After that's enabled, use the `SANITIZE_*` flag to enable individual sanitizers. (#6493) - Dev: Make code sanitizers opt in with the `CHATTERINO_SANITIZER_SUPPORT` CMake option. After that's enabled, use the `SANITIZE_*` flag to enable individual sanitizers. (#6493)
- Dev: Remove unused QTextCodec includes. (#6487) - Dev: Remove unused QTextCodec includes. (#6487)
@@ -167,13 +167,18 @@ void WebSocketConnectionHelper<Derived, Inner>::doWsHandshake()
auto host = this->options.url.host(QUrl::FullyEncoded).toStdString() + ':' + auto host = this->options.url.host(QUrl::FullyEncoded).toStdString() + ':' +
std::to_string(this->options.url.port(Derived::DEFAULT_PORT)); std::to_string(this->options.url.port(Derived::DEFAULT_PORT));
auto path = this->options.url.path(QUrl::FullyEncoded).toStdString(); auto path = this->options.url.path(QUrl::FullyEncoded);
if (path.empty()) if (path.isEmpty())
{ {
path = "/"; path = "/";
} }
if (this->options.url.hasQuery())
{
path += '?';
path += this->options.url.query(QUrl::FullyEncoded);
}
this->stream.async_handshake( this->stream.async_handshake(
host, path, host, path.toStdString(),
beast::bind_front_handler(&WebSocketConnectionHelper::onWsHandshake, beast::bind_front_handler(&WebSocketConnectionHelper::onWsHandshake,
this->shared_from_this())); this->shared_from_this()));
} }
+9 -3
View File
@@ -61,7 +61,7 @@ TEST(WebSocketPool, tcpEcho)
auto handle = pool.createSocket( auto handle = pool.createSocket(
{ {
.url = QUrl("ws://127.0.0.1:9052/echo"), .url = QUrl("ws://127.0.0.1:9052/echo?query=123&xd=wow"),
.headers = .headers =
{ {
{"My-Header", "my-header-VALUE"}, {"My-Header", "my-header-VALUE"},
@@ -85,11 +85,12 @@ TEST(WebSocketPool, tcpEcho)
handle.sendText("/HEADER another-header"); handle.sendText("/HEADER another-header");
handle.sendText("/HEADER cookie"); handle.sendText("/HEADER cookie");
handle.sendText("/HEADER user-agent"); handle.sendText("/HEADER user-agent");
handle.sendText("/URL");
handle.sendText("/CLOSE"); handle.sendText("/CLOSE");
ASSERT_TRUE(closeFlag.waitFor(1s)); ASSERT_TRUE(closeFlag.waitFor(1s));
ASSERT_EQ(messages.size(), 10); ASSERT_EQ(messages.size(), 11);
ASSERT_EQ(messages[0].first, false); ASSERT_EQ(messages[0].first, false);
ASSERT_EQ(messages[0].second, "message1"); ASSERT_EQ(messages[0].second, "message1");
ASSERT_EQ(messages[1].first, false); ASSERT_EQ(messages[1].first, false);
@@ -110,6 +111,8 @@ TEST(WebSocketPool, tcpEcho)
ASSERT_EQ(messages[8].second, "xd"); ASSERT_EQ(messages[8].second, "xd");
ASSERT_EQ(messages[9].first, true); ASSERT_EQ(messages[9].first, true);
ASSERT_EQ(messages[9].second, "MyUserAgent"); ASSERT_EQ(messages[9].second, "MyUserAgent");
ASSERT_EQ(messages[10].first, true);
ASSERT_EQ(messages[10].second, "/echo?query=123&xd=wow");
} }
TEST(WebSocketPool, tlsEcho) TEST(WebSocketPool, tlsEcho)
@@ -146,11 +149,12 @@ TEST(WebSocketPool, tlsEcho)
handle.sendText("/HEADER another-header"); handle.sendText("/HEADER another-header");
handle.sendText("/HEADER cookie"); handle.sendText("/HEADER cookie");
handle.sendText("/HEADER user-agent"); handle.sendText("/HEADER user-agent");
handle.sendText("/URL");
handle.sendText("/CLOSE"); handle.sendText("/CLOSE");
ASSERT_TRUE(closeFlag.waitFor(1s)); ASSERT_TRUE(closeFlag.waitFor(1s));
ASSERT_EQ(messages.size(), 10); ASSERT_EQ(messages.size(), 11);
ASSERT_EQ(messages[0].first, false); ASSERT_EQ(messages[0].first, false);
ASSERT_EQ(messages[0].second, "message1"); ASSERT_EQ(messages[0].second, "message1");
ASSERT_EQ(messages[1].first, false); ASSERT_EQ(messages[1].first, false);
@@ -171,4 +175,6 @@ TEST(WebSocketPool, tlsEcho)
ASSERT_EQ(messages[8].second, "xd"); ASSERT_EQ(messages[8].second, "xd");
ASSERT_EQ(messages[9].first, true); ASSERT_EQ(messages[9].first, true);
ASSERT_TRUE(messages[9].second.startsWith("Chatterino")); ASSERT_TRUE(messages[9].second.startsWith("Chatterino"));
ASSERT_EQ(messages[10].first, true);
ASSERT_EQ(messages[10].second, "/echo");
} }