[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" |
Ramin Halavati | 90aa08ba | 2018-02-07 06:16:16 | [diff] [blame^] | 13 | #include "net/traffic_annotation/network_traffic_annotation.h" |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 14 | |
15 | namespace net { | ||||
16 | |||||
17 | class HttpConnection; | ||||
byungchul | 38c3ae7 | 2014-08-25 23:27:46 | [diff] [blame] | 18 | class HttpServer; |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 19 | class HttpServerRequestInfo; |
yhirano | 995e964 | 2015-09-09 09:01:20 | [diff] [blame] | 20 | class WebSocketEncoder; |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 21 | |
yhirano | 995e964 | 2015-09-09 09:01:20 | [diff] [blame] | 22 | class WebSocket final { |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 23 | public: |
24 | enum ParseResult { | ||||
25 | FRAME_OK, | ||||
26 | FRAME_INCOMPLETE, | ||||
[email protected] | c51ab12 | 2011-09-26 16:14:49 | [diff] [blame] | 27 | FRAME_CLOSE, |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 28 | FRAME_ERROR |
29 | }; | ||||
30 | |||||
yhirano | a10dd4e | 2015-09-28 09:06:34 | [diff] [blame] | 31 | WebSocket(HttpServer* server, HttpConnection* connection); |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 32 | |
Ramin Halavati | 90aa08ba | 2018-02-07 06:16:16 | [diff] [blame^] | 33 | void Accept(const HttpServerRequestInfo& request, |
34 | const NetworkTrafficAnnotationTag traffic_annotation); | ||||
yhirano | 995e964 | 2015-09-09 09:01:20 | [diff] [blame] | 35 | ParseResult Read(std::string* message); |
Ramin Halavati | 90aa08ba | 2018-02-07 06:16:16 | [diff] [blame^] | 36 | void Send(const std::string& message, |
37 | const NetworkTrafficAnnotationTag traffic_annotation); | ||||
yhirano | 995e964 | 2015-09-09 09:01:20 | [diff] [blame] | 38 | ~WebSocket(); |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 39 | |
yhirano | 995e964 | 2015-09-09 09:01:20 | [diff] [blame] | 40 | private: |
yhirano | a10dd4e | 2015-09-28 09:06:34 | [diff] [blame] | 41 | void Fail(); |
Ramin Halavati | 90aa08ba | 2018-02-07 06:16:16 | [diff] [blame^] | 42 | void SendErrorResponse(const std::string& message, |
43 | const NetworkTrafficAnnotationTag traffic_annotation); | ||||
byungchul | 38c3ae7 | 2014-08-25 23:27:46 | [diff] [blame] | 44 | |
45 | HttpServer* const server_; | ||||
46 | HttpConnection* const connection_; | ||||
danakj | a9850e1 | 2016-04-18 22:28:08 | [diff] [blame] | 47 | std::unique_ptr<WebSocketEncoder> encoder_; |
yhirano | 995e964 | 2015-09-09 09:01:20 | [diff] [blame] | 48 | bool closed_; |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 49 | |
[email protected] | 86c6a0b5 | 2011-08-02 19:49:25 | [diff] [blame] | 50 | DISALLOW_COPY_AND_ASSIGN(WebSocket); |
51 | }; | ||||
52 | |||||
53 | } // namespace net | ||||
54 | |||||
[email protected] | 0cfad2f3 | 2012-05-17 06:40:39 | [diff] [blame] | 55 | #endif // NET_SERVER_WEB_SOCKET_H_ |