| 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 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "net/websockets/websocket_handshake_handler.h" | 26 #include "net/websockets/websocket_handshake_handler.h" |
| 27 #include "net/websockets/websocket_stream.h" | 27 #include "net/websockets/websocket_stream.h" |
| 28 | 28 |
| 29 namespace net { | 29 namespace net { |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 std::string GenerateHandshakeChallenge() { | 32 std::string GenerateHandshakeChallenge() { |
| 33 std::string raw_challenge(websockets::kRawChallengeLength, '\0'); | 33 std::string raw_challenge(websockets::kRawChallengeLength, '\0'); |
| 34 crypto::RandBytes(string_as_array(&raw_challenge), raw_challenge.length()); | 34 crypto::RandBytes(string_as_array(&raw_challenge), raw_challenge.length()); |
| 35 std::string encoded_challenge; | 35 std::string encoded_challenge; |
| 36 base::Base64Encode(raw_challenge, &encoded_challenge); | 36 bool encode_success = base::Base64Encode(raw_challenge, &encoded_challenge); |
| 37 DCHECK(encode_success); |
| 37 return encoded_challenge; | 38 return encoded_challenge; |
| 38 } | 39 } |
| 39 | 40 |
| 40 void AddVectorHeaderIfNonEmpty(const char* name, | 41 void AddVectorHeaderIfNonEmpty(const char* name, |
| 41 const std::vector<std::string>& value, | 42 const std::vector<std::string>& value, |
| 42 HttpRequestHeaders* headers) { | 43 HttpRequestHeaders* headers) { |
| 43 if (value.empty()) | 44 if (value.empty()) |
| 44 return; | 45 return; |
| 45 headers->SetHeader(name, JoinString(value, ", ")); | 46 headers->SetHeader(name, JoinString(value, ", ")); |
| 46 } | 47 } |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 headers->HasHeaderValue(HttpRequestHeaders::kConnection, | 306 headers->HasHeaderValue(HttpRequestHeaders::kConnection, |
| 306 websockets::kUpgrade) && | 307 websockets::kUpgrade) && |
| 307 ValidateSubProtocol(headers, requested_sub_protocols_, &sub_protocol_) && | 308 ValidateSubProtocol(headers, requested_sub_protocols_, &sub_protocol_) && |
| 308 ValidateExtensions(headers, requested_extensions_, &extensions_)) { | 309 ValidateExtensions(headers, requested_extensions_, &extensions_)) { |
| 309 return OK; | 310 return OK; |
| 310 } | 311 } |
| 311 return ERR_INVALID_RESPONSE; | 312 return ERR_INVALID_RESPONSE; |
| 312 } | 313 } |
| 313 | 314 |
| 314 } // namespace net | 315 } // namespace net |
| OLD | NEW |