• 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 #ifndef NET_TEST_EMBEDDED_TEST_SERVER_WEBSOCKET_CLOSE_HANDLER_H_
6 #define NET_TEST_EMBEDDED_TEST_SERVER_WEBSOCKET_CLOSE_HANDLER_H_
7 
8 #include <memory>
9 #include <string_view>
10 
11 #include "base/memory/scoped_refptr.h"
12 #include "net/test/embedded_test_server/embedded_test_server.h"
13 #include "net/test/embedded_test_server/websocket_connection.h"
14 #include "net/test/embedded_test_server/websocket_handler.h"
15 
16 namespace net::test_server {
17 
18 // WebSocketCloseHandler is a handler for WebSocket connections that closes on
19 // receiving "Goodbye" and passively handles closing handshakes by returning the
20 // close code and reason.
21 class WebSocketCloseHandler : public WebSocketHandler {
22  public:
23   // Constructs the handler with a given WebSocket connection.
24   explicit WebSocketCloseHandler(scoped_refptr<WebSocketConnection> connection);
25 
26   ~WebSocketCloseHandler() override;
27 
28   // Receives messages. Closes on "Goodbye" text.
29   void OnTextMessage(std::string_view message) override;
30 };
31 
32 }  // namespace net::test_server
33 
34 #endif  // NET_TEST_EMBEDDED_TEST_SERVER_WEBSOCKET_CLOSE_HANDLER_H_
35