| 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_basic_handshake_stream.h" | 5 #include "net/websockets/websocket_basic_handshake_stream.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <iterator> | 9 #include <iterator> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <unordered_set> |
| 12 #include <utility> | 13 #include <utility> |
| 13 #include <vector> | 14 #include <vector> |
| 14 | 15 |
| 15 #include "base/base64.h" | 16 #include "base/base64.h" |
| 16 #include "base/bind.h" | 17 #include "base/bind.h" |
| 17 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
| 18 #include "base/containers/hash_tables.h" | |
| 19 #include "base/logging.h" | 19 #include "base/logging.h" |
| 20 #include "base/metrics/histogram_macros.h" | 20 #include "base/metrics/histogram_macros.h" |
| 21 #include "base/metrics/sparse_histogram.h" | 21 #include "base/metrics/sparse_histogram.h" |
| 22 #include "base/stl_util.h" | 22 #include "base/stl_util.h" |
| 23 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
| 24 #include "base/strings/string_piece.h" | 24 #include "base/strings/string_piece.h" |
| 25 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
| 26 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
| 27 #include "base/time/time.h" | 27 #include "base/time/time.h" |
| 28 #include "crypto/random.h" | 28 #include "crypto/random.h" |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 return true; | 180 return true; |
| 181 } | 181 } |
| 182 | 182 |
| 183 bool ValidateSubProtocol( | 183 bool ValidateSubProtocol( |
| 184 const HttpResponseHeaders* headers, | 184 const HttpResponseHeaders* headers, |
| 185 const std::vector<std::string>& requested_sub_protocols, | 185 const std::vector<std::string>& requested_sub_protocols, |
| 186 std::string* sub_protocol, | 186 std::string* sub_protocol, |
| 187 std::string* failure_message) { | 187 std::string* failure_message) { |
| 188 size_t iter = 0; | 188 size_t iter = 0; |
| 189 std::string value; | 189 std::string value; |
| 190 base::hash_set<std::string> requested_set(requested_sub_protocols.begin(), | 190 std::unordered_set<std::string> requested_set(requested_sub_protocols.begin(), |
| 191 requested_sub_protocols.end()); | 191 requested_sub_protocols.end()); |
| 192 int count = 0; | 192 int count = 0; |
| 193 bool has_multiple_protocols = false; | 193 bool has_multiple_protocols = false; |
| 194 bool has_invalid_protocol = false; | 194 bool has_invalid_protocol = false; |
| 195 | 195 |
| 196 while (!has_invalid_protocol || !has_multiple_protocols) { | 196 while (!has_invalid_protocol || !has_multiple_protocols) { |
| 197 std::string temp_value; | 197 std::string temp_value; |
| 198 if (!headers->EnumerateHeader(&iter, websockets::kSecWebSocketProtocol, | 198 if (!headers->EnumerateHeader(&iter, websockets::kSecWebSocketProtocol, |
| 199 &temp_value)) | 199 &temp_value)) |
| 200 break; | 200 break; |
| 201 value = temp_value; | 201 value = temp_value; |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 set_failure_message("Error during WebSocket handshake: " + failure_message); | 597 set_failure_message("Error during WebSocket handshake: " + failure_message); |
| 598 return ERR_INVALID_RESPONSE; | 598 return ERR_INVALID_RESPONSE; |
| 599 } | 599 } |
| 600 | 600 |
| 601 void WebSocketBasicHandshakeStream::set_failure_message( | 601 void WebSocketBasicHandshakeStream::set_failure_message( |
| 602 const std::string& failure_message) { | 602 const std::string& failure_message) { |
| 603 *failure_message_ = failure_message; | 603 *failure_message_ = failure_message; |
| 604 } | 604 } |
| 605 | 605 |
| 606 } // namespace net | 606 } // namespace net |
| OLD | NEW |