|
@@ -24061,6 +24061,18 @@ protected:
|
|
|
}
|
|
}
|
|
|
return "";
|
|
return "";
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+ server_->WebSocket(
|
|
|
|
|
+ "/ws-subprotocol-unoffered",
|
|
|
|
|
+ [](const Request &, ws::WebSocket &ws) {
|
|
|
|
|
+ std::string msg;
|
|
|
|
|
+ while (ws.read(msg)) {
|
|
|
|
|
+ ws.send(msg);
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ [](const std::vector<std::string> &) -> std::string {
|
|
|
|
|
+ return "admin";
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void start_server() {
|
|
void start_server() {
|
|
@@ -24403,6 +24415,18 @@ TEST_F(WebSocketIntegrationTest, SubProtocolNoMatch) {
|
|
|
client.close();
|
|
client.close();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+TEST_F(WebSocketIntegrationTest, SubProtocolSelectorReturnsUnoffered) {
|
|
|
|
|
+ Headers headers = {{"Sec-WebSocket-Protocol", "chat"}};
|
|
|
|
|
+ ws::WebSocketClient client("ws://localhost:" + std::to_string(port_) +
|
|
|
|
|
+ "/ws-subprotocol-unoffered",
|
|
|
|
|
+ headers);
|
|
|
|
|
+ ASSERT_TRUE(client.connect());
|
|
|
|
|
+
|
|
|
|
|
+ EXPECT_TRUE(client.subprotocol().empty());
|
|
|
|
|
+
|
|
|
|
|
+ client.close();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
TEST_F(WebSocketIntegrationTest, SubProtocolNotRequested) {
|
|
TEST_F(WebSocketIntegrationTest, SubProtocolNotRequested) {
|
|
|
// Connect without requesting any subprotocol
|
|
// Connect without requesting any subprotocol
|
|
|
ws::WebSocketClient client("ws://localhost:" + std::to_string(port_) +
|
|
ws::WebSocketClient client("ws://localhost:" + std::to_string(port_) +
|