1 // Copyright 2014 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_ENCODER_H_
6 #define NET_SERVER_WEB_SOCKET_ENCODER_H_
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string_piece.h"
13 #include "net/server/web_socket.h"
14 #include "net/websockets/websocket_deflater.h"
15 #include "net/websockets/websocket_inflater.h"
19 class WebSocketEncoder
{
23 static WebSocketEncoder
* CreateServer(const std::string
& request_extensions
,
24 std::string
* response_extensions
);
26 static const char kClientExtensions
[];
27 static WebSocketEncoder
* CreateClient(const std::string
& response_extensions
);
29 WebSocket::ParseResult
DecodeFrame(const base::StringPiece
& frame
,
33 void EncodeFrame(const std::string
& frame
,
38 explicit WebSocketEncoder(bool is_server
);
39 WebSocketEncoder(bool is_server
,
42 bool no_context_takeover
);
44 // Parses a value in the Sec-WebSocket-Extensions header. If it contains a
45 // single element of the permessage-deflate extension, stores the result of
46 // parsing the parameters of the extension into the given variables.
47 // Otherwise, returns with *deflate set to false.
49 // - If the client_max_window_bits parameter is missing, *client_window_bits
51 // - If the client_max_window_bits parameter has an invalid value,
52 // *client_window_bits will be set to 0.
53 // - If the server_max_window_bits parameter is missing, *server_window_bits
55 // - If the server_max_window_bits parameter has an invalid value,
56 // *client_window_bits will be set to 0.
58 // TODO(tyoshino): Consider using a struct than taking a lot of pointers for
60 static void ParseExtensions(const std::string
& header_value
,
62 bool* has_client_window_bits
,
63 int* client_window_bits
,
64 int* server_window_bits
,
65 bool* client_no_context_takeover
,
66 bool* server_no_context_takeover
);
68 bool Inflate(std::string
* message
);
69 bool Deflate(const std::string
& message
, std::string
* output
);
71 scoped_ptr
<WebSocketDeflater
> deflater_
;
72 scoped_ptr
<WebSocketInflater
> inflater_
;
75 DISALLOW_COPY_AND_ASSIGN(WebSocketEncoder
);
80 #endif // NET_SERVER_WEB_SOCKET_ENCODER_H_