| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 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_SOCKET_WEB_SOCKET_SERVER_SOCKET_H_ | |
| 6 #define NET_SOCKET_WEB_SOCKET_SERVER_SOCKET_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "net/base/net_export.h" | |
| 12 #include "net/socket/socket.h" | |
| 13 | |
| 14 namespace net { | |
| 15 | |
| 16 // WebSocketServerSocket takes an (already connected) underlying transport | |
| 17 // socket and speaks server-side websocket protocol atop of it. | |
| 18 // This class implements Socket interface: notice that Read() returns (or calls | |
| 19 // back) as soon as some amount of data is available, even if message/frame is | |
| 20 // incomplete. | |
| 21 class WebSocketServerSocket : public Socket { | |
| 22 public: | |
| 23 class Delegate { | |
| 24 public: | |
| 25 // Validates websocket handshake: return false to reject handshake. | |
| 26 // |resource| is name of resource requested in GET stanza of handshake; | |
| 27 // |origin| is origin as reported in handshake; | |
| 28 // |host| is Host field from handshake; | |
| 29 // |subprotocol_list| is derived from Sec-WebSocket-Protocol field. | |
| 30 // Output parameters are: | |
| 31 // |location_out| is location of websocket server; | |
| 32 // |subprotocol_out| is selected subprotocol (or empty string if subprotocol | |
| 33 // list is empty. | |
| 34 virtual bool ValidateWebSocket( | |
| 35 const std::string& resource, | |
| 36 const std::string& origin, | |
| 37 const std::string& host, | |
| 38 const std::vector<std::string>& subprotocol_list, | |
| 39 std::string* location_out, | |
| 40 std::string* subprotocol_out) = 0; | |
| 41 | |
| 42 virtual ~Delegate() {} | |
| 43 }; | |
| 44 | |
| 45 virtual ~WebSocketServerSocket(); | |
| 46 | |
| 47 // Performs websocket server handshake on transport socket. Underlying socket | |
| 48 // must have already been connected/accepted. | |
| 49 // | |
| 50 // Returns either ERR_IO_PENDING, in which case the given callback will be | |
| 51 // called in the future with the real result, or it completes synchronously, | |
| 52 // returning the result immediately. | |
| 53 virtual int Accept(const CompletionCallback& callback) = 0; | |
| 54 }; | |
| 55 | |
| 56 // Creates websocket server socket atop of already connected socket. This | |
| 57 // created server socket will take ownership of |transport_socket|. | |
| 58 NET_EXPORT WebSocketServerSocket* CreateWebSocketServerSocket( | |
| 59 Socket* transport_socket, | |
| 60 WebSocketServerSocket::Delegate* delegate); | |
| 61 | |
| 62 } // namespace net | |
| 63 | |
| 64 #endif // NET_SOCKET_WEB_SOCKET_SERVER_SOCKET_H_ | |
| OLD | NEW |