OLD | NEW |
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" |
(...skipping 27 matching lines...) Expand all Loading... |
38 std::multimap<std::string, std::string> this_parameters, other_parameters; | 38 std::multimap<std::string, std::string> this_parameters, other_parameters; |
39 for (const auto& p : parameters_) { | 39 for (const auto& p : parameters_) { |
40 this_parameters.insert(std::make_pair(p.name(), p.value())); | 40 this_parameters.insert(std::make_pair(p.name(), p.value())); |
41 } | 41 } |
42 for (const auto& p : other.parameters_) { | 42 for (const auto& p : other.parameters_) { |
43 other_parameters.insert(std::make_pair(p.name(), p.value())); | 43 other_parameters.insert(std::make_pair(p.name(), p.value())); |
44 } | 44 } |
45 return this_parameters == other_parameters; | 45 return this_parameters == other_parameters; |
46 } | 46 } |
47 | 47 |
| 48 std::string WebSocketExtension::ToString() const { |
| 49 if (name_.empty()) { |
| 50 return std::string(); |
| 51 } |
| 52 |
| 53 std::string result = name_; |
| 54 |
| 55 for (const auto& param : parameters_) { |
| 56 result += "; " + param.name(); |
| 57 if (!param.HasValue()) |
| 58 continue; |
| 59 |
| 60 result += "="; |
| 61 const auto& value = param.value(); |
| 62 if (value.find('"') == std::string::npos) { |
| 63 result += value; |
| 64 } else { |
| 65 result += '"'; |
| 66 for (const auto& c : value) { |
| 67 if (c == '"') { |
| 68 result += "\\\""; |
| 69 } else { |
| 70 result += c; |
| 71 } |
| 72 } |
| 73 result += '"'; |
| 74 } |
| 75 } |
| 76 return result; |
| 77 } |
| 78 |
48 } // namespace net | 79 } // namespace net |
OLD | NEW |