| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 std::string encoded_challenge; | 92 std::string encoded_challenge; |
| 93 base::Base64Encode(raw_challenge, &encoded_challenge); | 93 base::Base64Encode(raw_challenge, &encoded_challenge); |
| 94 return encoded_challenge; | 94 return encoded_challenge; |
| 95 } | 95 } |
| 96 | 96 |
| 97 void AddVectorHeaderIfNonEmpty(const char* name, | 97 void AddVectorHeaderIfNonEmpty(const char* name, |
| 98 const std::vector<std::string>& value, | 98 const std::vector<std::string>& value, |
| 99 HttpRequestHeaders* headers) { | 99 HttpRequestHeaders* headers) { |
| 100 if (value.empty()) | 100 if (value.empty()) |
| 101 return; | 101 return; |
| 102 headers->SetHeader(name, base::JoinString(value, ", ")); | 102 headers->SetHeader(name, JoinString(value, ", ")); |
| 103 } | 103 } |
| 104 | 104 |
| 105 GetHeaderResult GetSingleHeaderValue(const HttpResponseHeaders* headers, | 105 GetHeaderResult GetSingleHeaderValue(const HttpResponseHeaders* headers, |
| 106 const base::StringPiece& name, | 106 const base::StringPiece& name, |
| 107 std::string* value) { | 107 std::string* value) { |
| 108 void* state = nullptr; | 108 void* state = nullptr; |
| 109 size_t num_values = 0; | 109 size_t num_values = 0; |
| 110 std::string temp_value; | 110 std::string temp_value; |
| 111 while (headers->EnumerateHeader(&state, name, &temp_value)) { | 111 while (headers->EnumerateHeader(&state, name, &temp_value)) { |
| 112 if (++num_values > 1) | 112 if (++num_values > 1) |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 } | 339 } |
| 340 header_values.push_back(header_value); | 340 header_values.push_back(header_value); |
| 341 } else { | 341 } else { |
| 342 *failure_message = "Found an unsupported extension '" + | 342 *failure_message = "Found an unsupported extension '" + |
| 343 extension.name() + | 343 extension.name() + |
| 344 "' in 'Sec-WebSocket-Extensions' header"; | 344 "' in 'Sec-WebSocket-Extensions' header"; |
| 345 return false; | 345 return false; |
| 346 } | 346 } |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 *accepted_extensions_descriptor = base::JoinString(header_values, ", "); | 349 *accepted_extensions_descriptor = JoinString(header_values, ", "); |
| 350 return true; | 350 return true; |
| 351 } | 351 } |
| 352 | 352 |
| 353 } // namespace | 353 } // namespace |
| 354 | 354 |
| 355 WebSocketBasicHandshakeStream::WebSocketBasicHandshakeStream( | 355 WebSocketBasicHandshakeStream::WebSocketBasicHandshakeStream( |
| 356 scoped_ptr<ClientSocketHandle> connection, | 356 scoped_ptr<ClientSocketHandle> connection, |
| 357 WebSocketStream::ConnectDelegate* connect_delegate, | 357 WebSocketStream::ConnectDelegate* connect_delegate, |
| 358 bool using_proxy, | 358 bool using_proxy, |
| 359 std::vector<std::string> requested_sub_protocols, | 359 std::vector<std::string> requested_sub_protocols, |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 set_failure_message("Error during WebSocket handshake: " + failure_message); | 647 set_failure_message("Error during WebSocket handshake: " + failure_message); |
| 648 return ERR_INVALID_RESPONSE; | 648 return ERR_INVALID_RESPONSE; |
| 649 } | 649 } |
| 650 | 650 |
| 651 void WebSocketBasicHandshakeStream::set_failure_message( | 651 void WebSocketBasicHandshakeStream::set_failure_message( |
| 652 const std::string& failure_message) { | 652 const std::string& failure_message) { |
| 653 *failure_message_ = failure_message; | 653 *failure_message_ = failure_message; |
| 654 } | 654 } |
| 655 | 655 |
| 656 } // namespace net | 656 } // namespace net |
| OLD | NEW |