Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / net / server / web_socket.h
blob9b3a794452af27537752c08bffad4a3431d4fcae
1 // Copyright (c) 2012 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.
5 #ifndef NET_SERVER_WEB_SOCKET_H_
6 #define NET_SERVER_WEB_SOCKET_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/strings/string_piece.h"
13 namespace net {
15 class HttpConnection;
16 class HttpServer;
17 class HttpServerRequestInfo;
19 class WebSocket {
20 public:
21 enum ParseResult {
22 FRAME_OK,
23 FRAME_INCOMPLETE,
24 FRAME_CLOSE,
25 FRAME_ERROR
28 static WebSocket* CreateWebSocket(HttpServer* server,
29 HttpConnection* connection,
30 const HttpServerRequestInfo& request,
31 size_t* pos);
33 static ParseResult DecodeFrameHybi17(const base::StringPiece& frame,
34 bool client_frame,
35 int* bytes_consumed,
36 std::string* output);
38 static std::string EncodeFrameHybi17(const std::string& data,
39 int masking_key);
41 virtual void Accept(const HttpServerRequestInfo& request) = 0;
42 virtual ParseResult Read(std::string* message) = 0;
43 virtual void Send(const std::string& message) = 0;
44 virtual ~WebSocket() {}
46 protected:
47 WebSocket(HttpServer* server, HttpConnection* connection);
49 HttpServer* const server_;
50 HttpConnection* const connection_;
52 private:
53 DISALLOW_COPY_AND_ASSIGN(WebSocket);
56 } // namespace net
58 #endif // NET_SERVER_WEB_SOCKET_H_