blob: 6d57a7df7475718c7c1424163c6ada75e24e888e [file] [log] [blame]
[email protected]0cfad2f32012-05-17 06:40:391// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]86c6a0b52011-08-02 19:49:252// 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_SERVER_WEB_SOCKET_H_
6#define NET_SERVER_WEB_SOCKET_H_
[email protected]86c6a0b52011-08-02 19:49:257
danakja9850e12016-04-18 22:28:088#include <memory>
[email protected]86c6a0b52011-08-02 19:49:259#include <string>
10
Avi Drissman13fc8932015-12-20 04:40:4611#include "base/macros.h"
byungchul38c3ae72014-08-25 23:27:4612#include "base/strings/string_piece.h"
Ramin Halavati90aa08ba2018-02-07 06:16:1613#include "net/traffic_annotation/network_traffic_annotation.h"
[email protected]86c6a0b52011-08-02 19:49:2514
15namespace net {
16
17class HttpConnection;
byungchul38c3ae72014-08-25 23:27:4618class HttpServer;
[email protected]86c6a0b52011-08-02 19:49:2519class HttpServerRequestInfo;
yhirano995e9642015-09-09 09:01:2020class WebSocketEncoder;
[email protected]86c6a0b52011-08-02 19:49:2521
yhirano995e9642015-09-09 09:01:2022class WebSocket final {
[email protected]86c6a0b52011-08-02 19:49:2523 public:
24 enum ParseResult {
25 FRAME_OK,
26 FRAME_INCOMPLETE,
[email protected]c51ab122011-09-26 16:14:4927 FRAME_CLOSE,
[email protected]86c6a0b52011-08-02 19:49:2528 FRAME_ERROR
29 };
30
yhiranoa10dd4e2015-09-28 09:06:3431 WebSocket(HttpServer* server, HttpConnection* connection);
[email protected]86c6a0b52011-08-02 19:49:2532
Ramin Halavati90aa08ba2018-02-07 06:16:1633 void Accept(const HttpServerRequestInfo& request,
34 const NetworkTrafficAnnotationTag traffic_annotation);
yhirano995e9642015-09-09 09:01:2035 ParseResult Read(std::string* message);
Ramin Halavati90aa08ba2018-02-07 06:16:1636 void Send(const std::string& message,
37 const NetworkTrafficAnnotationTag traffic_annotation);
yhirano995e9642015-09-09 09:01:2038 ~WebSocket();
[email protected]86c6a0b52011-08-02 19:49:2539
yhirano995e9642015-09-09 09:01:2040 private:
yhiranoa10dd4e2015-09-28 09:06:3441 void Fail();
Ramin Halavati90aa08ba2018-02-07 06:16:1642 void SendErrorResponse(const std::string& message,
43 const NetworkTrafficAnnotationTag traffic_annotation);
byungchul38c3ae72014-08-25 23:27:4644
45 HttpServer* const server_;
46 HttpConnection* const connection_;
danakja9850e12016-04-18 22:28:0847 std::unique_ptr<WebSocketEncoder> encoder_;
yhirano995e9642015-09-09 09:01:2048 bool closed_;
[email protected]86c6a0b52011-08-02 19:49:2549
[email protected]86c6a0b52011-08-02 19:49:2550 DISALLOW_COPY_AND_ASSIGN(WebSocket);
51};
52
53} // namespace net
54
[email protected]0cfad2f32012-05-17 06:40:3955#endif // NET_SERVER_WEB_SOCKET_H_