Update Crashpad to 1baff4ff92fe1a1ead6b88b5f01633a4f0b6b51c.
[chromium-blink-merge.git] / net / server / web_socket_encoder.h
blob23f0d9cc075b15471ce7c3ef0b54f877f9be809a
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_
8 #include <string>
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"
17 namespace net {
19 class WebSocketEncoder {
20 public:
21 ~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,
30 int* bytes_consumed,
31 std::string* output);
33 void EncodeFrame(const std::string& frame,
34 int masking_key,
35 std::string* output);
37 private:
38 explicit WebSocketEncoder(bool is_server);
39 WebSocketEncoder(bool is_server,
40 int deflate_bits,
41 int inflate_bits,
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
50 // defaults to 15.
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
54 // defaults to 15.
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
59 // output.
60 static void ParseExtensions(const std::string& header_value,
61 bool* deflate,
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_;
73 bool is_server_;
75 DISALLOW_COPY_AND_ASSIGN(WebSocketEncoder);
78 } // namespace net
80 #endif // NET_SERVER_WEB_SOCKET_ENCODER_H_