[email protected] | 0cfad2f3 | 2012-05-17 06:40:39 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 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_SERVER_WEB_SOCKET_H_ | ||||
6 | #define NET_SERVER_WEB_SOCKET_H_ | ||||
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 7 | |
danakj | a9850e1 | 2016-04-18 22:28:08 | [diff] [blame^] | 8 | #include <memory> |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 9 | #include <string> |
10 | |||||
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 11 | #include "base/macros.h" |
byungchul | 38c3ae7 | 2014-08-25 23:27:46 | [diff] [blame] | 12 | #include "base/strings/string_piece.h" |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 13 | |
14 | namespace net { | ||||
15 | |||||
16 | class HttpConnection; | ||||
byungchul | 38c3ae7 | 2014-08-25 23:27:46 | [diff] [blame] | 17 | class HttpServer; |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 18 | class HttpServerRequestInfo; |
yhirano | 995e964 | 2015-09-09 09:01:20 | [diff] [blame] | 19 | class WebSocketEncoder; |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 20 | |
yhirano | 995e964 | 2015-09-09 09:01:20 | [diff] [blame] | 21 | class WebSocket final { |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 22 | public: |
23 | enum ParseResult { | ||||
24 | FRAME_OK, | ||||
25 | FRAME_INCOMPLETE, | ||||
[email protected] | c51ab12 | 2011-09-26 16:14:49 | [diff] [blame] | 26 | FRAME_CLOSE, |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 27 | FRAME_ERROR |
28 | }; | ||||
29 | |||||
yhirano | a10dd4e | 2015-09-28 09:06:34 | [diff] [blame] | 30 | WebSocket(HttpServer* server, HttpConnection* connection); |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 31 | |
yhirano | 995e964 | 2015-09-09 09:01:20 | [diff] [blame] | 32 | void Accept(const HttpServerRequestInfo& request); |
33 | ParseResult Read(std::string* message); | ||||
34 | void Send(const std::string& message); | ||||
35 | ~WebSocket(); | ||||
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 36 | |
yhirano | 995e964 | 2015-09-09 09:01:20 | [diff] [blame] | 37 | private: |
yhirano | a10dd4e | 2015-09-28 09:06:34 | [diff] [blame] | 38 | void Fail(); |
39 | void SendErrorResponse(const std::string& message); | ||||
byungchul | 38c3ae7 | 2014-08-25 23:27:46 | [diff] [blame] | 40 | |
41 | HttpServer* const server_; | ||||
42 | HttpConnection* const connection_; | ||||
danakj | a9850e1 | 2016-04-18 22:28:08 | [diff] [blame^] | 43 | std::unique_ptr<WebSocketEncoder> encoder_; |
yhirano | 995e964 | 2015-09-09 09:01:20 | [diff] [blame] | 44 | bool closed_; |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 45 | |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 46 | DISALLOW_COPY_AND_ASSIGN(WebSocket); |
47 | }; | ||||
48 | |||||
49 | } // namespace net | ||||
50 | |||||
[email protected] | 0cfad2f3 | 2012-05-17 06:40:39 | [diff] [blame] | 51 | #endif // NET_SERVER_WEB_SOCKET_H_ |