Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: net/websockets/websocket_extension.cc

Issue 1340523002: Fix WebSocketServer extension parser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ws-constructor-fix
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/websockets/websocket_extension.h" 5 #include "net/websockets/websocket_extension.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "net/http/http_util.h"
11 12
12 namespace net { 13 namespace net {
13 14
14 WebSocketExtension::Parameter::Parameter(const std::string& name) 15 WebSocketExtension::Parameter::Parameter(const std::string& name)
15 : name_(name) {} 16 : name_(name) {}
16 17
17 WebSocketExtension::Parameter::Parameter(const std::string& name, 18 WebSocketExtension::Parameter::Parameter(const std::string& name,
18 const std::string& value) 19 const std::string& value)
19 : name_(name), value_(value) { 20 : name_(name), value_(value) {
20 DCHECK(!value.empty()); 21 DCHECK(!value.empty());
22 // |extension-param| must be a token.
23 DCHECK(HttpUtil::IsToken(value));
21 } 24 }
22 25
23 bool WebSocketExtension::Parameter::Equals(const Parameter& other) const { 26 bool WebSocketExtension::Parameter::Equals(const Parameter& other) const {
24 return name_ == other.name_ && value_ == other.value_; 27 return name_ == other.name_ && value_ == other.value_;
25 } 28 }
26 29
27 WebSocketExtension::WebSocketExtension() {} 30 WebSocketExtension::WebSocketExtension() {}
28 31
29 WebSocketExtension::WebSocketExtension(const std::string& name) 32 WebSocketExtension::WebSocketExtension(const std::string& name)
30 : name_(name) {} 33 : name_(name) {}
31 34
32 WebSocketExtension::~WebSocketExtension() {} 35 WebSocketExtension::~WebSocketExtension() {}
33 36
34 bool WebSocketExtension::Equals(const WebSocketExtension& other) const { 37 bool WebSocketExtension::Equals(const WebSocketExtension& other) const {
35 if (name_ != other.name_) return false; 38 if (name_ != other.name_) return false;
36 if (parameters_.size() != other.parameters_.size()) return false; 39 if (parameters_.size() != other.parameters_.size()) return false;
37 40
38 std::multimap<std::string, std::string> this_parameters, other_parameters; 41 std::multimap<std::string, std::string> this_parameters, other_parameters;
39 for (const auto& p : parameters_) { 42 for (const auto& p : parameters_) {
40 this_parameters.insert(std::make_pair(p.name(), p.value())); 43 this_parameters.insert(std::make_pair(p.name(), p.value()));
41 } 44 }
42 for (const auto& p : other.parameters_) { 45 for (const auto& p : other.parameters_) {
43 other_parameters.insert(std::make_pair(p.name(), p.value())); 46 other_parameters.insert(std::make_pair(p.name(), p.value()));
44 } 47 }
45 return this_parameters == other_parameters; 48 return this_parameters == other_parameters;
46 } 49 }
47 50
51 std::string WebSocketExtension::ToString() const {
52 if (name_.empty()) {
53 return std::string();
54 }
davidben 2015/09/22 19:44:02 Nit: no curlies
yhirano 2015/09/28 03:17:06 Done.
55
56 std::string result = name_;
57
58 for (const auto& param : parameters_) {
59 result += "; " + param.name();
60 if (!param.HasValue())
61 continue;
62
63 // |extension-param| must be a token and we don't need to quote it.
64 DCHECK(HttpUtil::IsToken(param.value()));
65 result += "=" + param.value();
66 }
67 return result;
68 }
69
48 } // namespace net 70 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698