Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(470)

Side by Side Diff: net/websockets/websocket_handshake_handler.cc

Issue 86913002: Make base::Base64Encode() return void (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: One more chromeos-specific fix. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/websockets/websocket_basic_handshake_stream.cc ('k') | remoting/base/rsa_key_pair.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_handshake_handler.h" 5 #include "net/websockets/websocket_handshake_handler.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/sha1.h" 10 #include "base/sha1.h"
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 return original_header_length_ > 0 && 344 return original_header_length_ > 0 &&
345 static_cast<size_t>(original_header_length_) <= original_.size(); 345 static_cast<size_t>(original_header_length_) <= original_.size();
346 } 346 }
347 347
348 void ComputeSecWebSocketAccept(const std::string& key, 348 void ComputeSecWebSocketAccept(const std::string& key,
349 std::string* accept) { 349 std::string* accept) {
350 DCHECK(accept); 350 DCHECK(accept);
351 351
352 std::string hash = 352 std::string hash =
353 base::SHA1HashString(key + websockets::kWebSocketGuid); 353 base::SHA1HashString(key + websockets::kWebSocketGuid);
354 bool encode_success = base::Base64Encode(hash, accept); 354 base::Base64Encode(hash, accept);
355 DCHECK(encode_success);
356 } 355 }
357 356
358 bool WebSocketHandshakeResponseHandler::ParseResponseInfo( 357 bool WebSocketHandshakeResponseHandler::ParseResponseInfo(
359 const HttpResponseInfo& response_info, 358 const HttpResponseInfo& response_info,
360 const std::string& challenge) { 359 const std::string& challenge) {
361 if (!response_info.headers.get()) 360 if (!response_info.headers.get())
362 return false; 361 return false;
363 362
364 // TODO(ricea): Eliminate all the reallocations and string copies. 363 // TODO(ricea): Eliminate all the reallocations and string copies.
365 std::string response_message; 364 std::string response_message;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 if (spdy_protocol_version <= 2) 397 if (spdy_protocol_version <= 2)
399 status = headers.find("status"); 398 status = headers.find("status");
400 else 399 else
401 status = headers.find(":status"); 400 status = headers.find(":status");
402 if (status == headers.end()) 401 if (status == headers.end())
403 return false; 402 return false;
404 403
405 std::string hash = 404 std::string hash =
406 base::SHA1HashString(challenge + websockets::kWebSocketGuid); 405 base::SHA1HashString(challenge + websockets::kWebSocketGuid);
407 std::string websocket_accept; 406 std::string websocket_accept;
408 bool encode_success = base::Base64Encode(hash, &websocket_accept); 407 base::Base64Encode(hash, &websocket_accept);
409 DCHECK(encode_success);
410 408
411 std::string response_message = base::StringPrintf( 409 std::string response_message = base::StringPrintf(
412 "%s %s\r\n", websockets::kHttpProtocolVersion, status->second.c_str()); 410 "%s %s\r\n", websockets::kHttpProtocolVersion, status->second.c_str());
413 411
414 AppendHeader( 412 AppendHeader(
415 websockets::kUpgrade, websockets::kWebSocketLowercase, &response_message); 413 websockets::kUpgrade, websockets::kWebSocketLowercase, &response_message);
416 AppendHeader( 414 AppendHeader(
417 HttpRequestHeaders::kConnection, websockets::kUpgrade, &response_message); 415 HttpRequestHeaders::kConnection, websockets::kUpgrade, &response_message);
418 AppendHeader( 416 AppendHeader(
419 websockets::kSecWebSocketAccept, websocket_accept, &response_message); 417 websockets::kSecWebSocketAccept, websocket_accept, &response_message);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 489
492 std::string WebSocketHandshakeResponseHandler::GetResponse() { 490 std::string WebSocketHandshakeResponseHandler::GetResponse() {
493 DCHECK(HasResponse()); 491 DCHECK(HasResponse());
494 DCHECK(!status_line_.empty()); 492 DCHECK(!status_line_.empty());
495 // headers_ might be empty for wrong response from server. 493 // headers_ might be empty for wrong response from server.
496 494
497 return status_line_ + headers_ + header_separator_; 495 return status_line_ + headers_ + header_separator_;
498 } 496 }
499 497
500 } // namespace net 498 } // namespace net
OLDNEW
« no previous file with comments | « net/websockets/websocket_basic_handshake_stream.cc ('k') | remoting/base/rsa_key_pair.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698