• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2024 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "net/test/embedded_test_server/websocket_close_handler.h"
6 
7 namespace net::test_server {
8 
WebSocketCloseHandler(scoped_refptr<WebSocketConnection> connection)9 WebSocketCloseHandler::WebSocketCloseHandler(
10     scoped_refptr<WebSocketConnection> connection)
11     : WebSocketHandler(std::move(connection)) {}
12 
13 WebSocketCloseHandler::~WebSocketCloseHandler() = default;
14 
OnTextMessage(std::string_view message)15 void WebSocketCloseHandler::OnTextMessage(std::string_view message) {
16   CHECK(connection());
17 
18   // If the message is "Goodbye", initiate a closing handshake.
19   if (message == "Goodbye") {
20     connection()->StartClosingHandshake(1000, "Goodbye");
21   }
22 }
23 
24 }  // namespace net::test_server
25