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 bool encode_success = base::Base64Encode(raw_challenge, &encoded_challenge); | 36 base::Base64Encode(raw_challenge, &encoded_challenge); |
37 DCHECK(encode_success); | |
38 return encoded_challenge; | 37 return encoded_challenge; |
39 } | 38 } |
40 | 39 |
41 void AddVectorHeaderIfNonEmpty(const char* name, | 40 void AddVectorHeaderIfNonEmpty(const char* name, |
42 const std::vector<std::string>& value, | 41 const std::vector<std::string>& value, |
43 HttpRequestHeaders* headers) { | 42 HttpRequestHeaders* headers) { |
44 if (value.empty()) | 43 if (value.empty()) |
45 return; | 44 return; |
46 headers->SetHeader(name, JoinString(value, ", ")); | 45 headers->SetHeader(name, JoinString(value, ", ")); |
47 } | 46 } |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 headers->HasHeaderValue(HttpRequestHeaders::kConnection, | 305 headers->HasHeaderValue(HttpRequestHeaders::kConnection, |
307 websockets::kUpgrade) && | 306 websockets::kUpgrade) && |
308 ValidateSubProtocol(headers, requested_sub_protocols_, &sub_protocol_) && | 307 ValidateSubProtocol(headers, requested_sub_protocols_, &sub_protocol_) && |
309 ValidateExtensions(headers, requested_extensions_, &extensions_)) { | 308 ValidateExtensions(headers, requested_extensions_, &extensions_)) { |
310 return OK; | 309 return OK; |
311 } | 310 } |
312 return ERR_INVALID_RESPONSE; | 311 return ERR_INVALID_RESPONSE; |
313 } | 312 } |
314 | 313 |
315 } // namespace net | 314 } // namespace net |
OLD | NEW |