blob: 4c42a76f3106f2f97515031751e28462e3be458c [file] [log] [blame]
[email protected]d28e67a2013-09-19 10:31:431// Copyright 2013 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_WEBSOCKETS_WEBSOCKET_EXTENSION_H_
6#define NET_WEBSOCKETS_WEBSOCKET_EXTENSION_H_
7
8#include <string>
9#include <vector>
10
11#include "net/base/net_export.h"
12
13namespace net {
14
15// A WebSocketExtension instance represents a WebSocket extension specified
16// in RFC6455.
17class NET_EXPORT_PRIVATE WebSocketExtension {
18 public:
19 // Note that RFC6455 does not allow a parameter with an empty value.
20 class NET_EXPORT_PRIVATE Parameter {
21 public:
22 // Construct a parameter which does not have a value.
23 explicit Parameter(const std::string& name);
24 // Construct a parameter with a non-empty value.
25 Parameter(const std::string& name, const std::string& value);
26
27 bool HasValue() const { return !value_.empty(); }
28 const std::string& name() const { return name_; }
29 const std::string& value() const { return value_; }
30 bool Equals(const Parameter& other) const;
31
32 // The default copy constructor and the assignment operator are defined:
33 // we need them.
34 private:
35 std::string name_;
36 std::string value_;
37 };
38
39 WebSocketExtension();
40 explicit WebSocketExtension(const std::string& name);
vmpstracd23b72016-02-26 21:08:5541 WebSocketExtension(const WebSocketExtension& other);
[email protected]d28e67a2013-09-19 10:31:4342 ~WebSocketExtension();
43
44 void Add(const Parameter& parameter) { parameters_.push_back(parameter); }
45 const std::string& name() const { return name_; }
46 const std::vector<Parameter>& parameters() const { return parameters_; }
47 bool Equals(const WebSocketExtension& other) const;
yhiranoa10dd4e2015-09-28 09:06:3448 std::string ToString() const;
[email protected]d28e67a2013-09-19 10:31:4349
50 // The default copy constructor and the assignment operator are defined:
51 // we need them.
52 private:
53 std::string name_;
54 std::vector<Parameter> parameters_;
55};
56
57} // namespace net
58
59#endif // NET_WEBSOCKETS_WEBSOCKET_EXTENSION_H_