blob: aa01f11e16334e4a2f2205abfb7476de5210f7b2 [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"
[email protected]86c6a0b52011-08-02 19:49:2513
14namespace net {
15
16class HttpConnection;
byungchul38c3ae72014-08-25 23:27:4617class HttpServer;
[email protected]86c6a0b52011-08-02 19:49:2518class HttpServerRequestInfo;
yhirano995e9642015-09-09 09:01:2019class WebSocketEncoder;
[email protected]86c6a0b52011-08-02 19:49:2520
yhirano995e9642015-09-09 09:01:2021class WebSocket final {
[email protected]86c6a0b52011-08-02 19:49:2522 public:
23 enum ParseResult {
24 FRAME_OK,
25 FRAME_INCOMPLETE,
[email protected]c51ab122011-09-26 16:14:4926 FRAME_CLOSE,
[email protected]86c6a0b52011-08-02 19:49:2527 FRAME_ERROR
28 };
29
yhiranoa10dd4e2015-09-28 09:06:3430 WebSocket(HttpServer* server, HttpConnection* connection);
[email protected]86c6a0b52011-08-02 19:49:2531
yhirano995e9642015-09-09 09:01:2032 void Accept(const HttpServerRequestInfo& request);
33 ParseResult Read(std::string* message);
34 void Send(const std::string& message);
35 ~WebSocket();
[email protected]86c6a0b52011-08-02 19:49:2536
yhirano995e9642015-09-09 09:01:2037 private:
yhiranoa10dd4e2015-09-28 09:06:3438 void Fail();
39 void SendErrorResponse(const std::string& message);
byungchul38c3ae72014-08-25 23:27:4640
41 HttpServer* const server_;
42 HttpConnection* const connection_;
danakja9850e12016-04-18 22:28:0843 std::unique_ptr<WebSocketEncoder> encoder_;
yhirano995e9642015-09-09 09:01:2044 bool closed_;
[email protected]86c6a0b52011-08-02 19:49:2545
[email protected]86c6a0b52011-08-02 19:49:2546 DISALLOW_COPY_AND_ASSIGN(WebSocket);
47};
48
49} // namespace net
50
[email protected]0cfad2f32012-05-17 06:40:3951#endif // NET_SERVER_WEB_SOCKET_H_