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

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, 2 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
« no previous file with comments | « net/websockets/websocket_extension.h ('k') | net/websockets/websocket_extension_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
55 std::string result = name_;
56
57 for (const auto& param : parameters_) {
58 result += "; " + param.name();
59 if (!param.HasValue())
60 continue;
61
62 // |extension-param| must be a token and we don't need to quote it.
63 DCHECK(HttpUtil::IsToken(param.value()));
64 result += "=" + param.value();
65 }
66 return result;
67 }
68
48 } // namespace net 69 } // namespace net
OLDNEW
« no previous file with comments | « net/websockets/websocket_extension.h ('k') | net/websockets/websocket_extension_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698