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

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

Issue 101113004: Revert 239759 "The comment in base64.h implies that base::Base64..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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 | Annotate | Revision Log
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 base::Base64Encode(hash, accept); 354 bool encode_success = base::Base64Encode(hash, accept);
355 DCHECK(encode_success);
355 } 356 }
356 357
357 bool WebSocketHandshakeResponseHandler::ParseResponseInfo( 358 bool WebSocketHandshakeResponseHandler::ParseResponseInfo(
358 const HttpResponseInfo& response_info, 359 const HttpResponseInfo& response_info,
359 const std::string& challenge) { 360 const std::string& challenge) {
360 if (!response_info.headers.get()) 361 if (!response_info.headers.get())
361 return false; 362 return false;
362 363
363 // TODO(ricea): Eliminate all the reallocations and string copies. 364 // TODO(ricea): Eliminate all the reallocations and string copies.
364 std::string response_message; 365 std::string response_message;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 if (spdy_protocol_version <= 2) 398 if (spdy_protocol_version <= 2)
398 status = headers.find("status"); 399 status = headers.find("status");
399 else 400 else
400 status = headers.find(":status"); 401 status = headers.find(":status");
401 if (status == headers.end()) 402 if (status == headers.end())
402 return false; 403 return false;
403 404
404 std::string hash = 405 std::string hash =
405 base::SHA1HashString(challenge + websockets::kWebSocketGuid); 406 base::SHA1HashString(challenge + websockets::kWebSocketGuid);
406 std::string websocket_accept; 407 std::string websocket_accept;
407 base::Base64Encode(hash, &websocket_accept); 408 bool encode_success = base::Base64Encode(hash, &websocket_accept);
409 DCHECK(encode_success);
408 410
409 std::string response_message = base::StringPrintf( 411 std::string response_message = base::StringPrintf(
410 "%s %s\r\n", websockets::kHttpProtocolVersion, status->second.c_str()); 412 "%s %s\r\n", websockets::kHttpProtocolVersion, status->second.c_str());
411 413
412 AppendHeader( 414 AppendHeader(
413 websockets::kUpgrade, websockets::kWebSocketLowercase, &response_message); 415 websockets::kUpgrade, websockets::kWebSocketLowercase, &response_message);
414 AppendHeader( 416 AppendHeader(
415 HttpRequestHeaders::kConnection, websockets::kUpgrade, &response_message); 417 HttpRequestHeaders::kConnection, websockets::kUpgrade, &response_message);
416 AppendHeader( 418 AppendHeader(
417 websockets::kSecWebSocketAccept, websocket_accept, &response_message); 419 websockets::kSecWebSocketAccept, websocket_accept, &response_message);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 491
490 std::string WebSocketHandshakeResponseHandler::GetResponse() { 492 std::string WebSocketHandshakeResponseHandler::GetResponse() {
491 DCHECK(HasResponse()); 493 DCHECK(HasResponse());
492 DCHECK(!status_line_.empty()); 494 DCHECK(!status_line_.empty());
493 // headers_ might be empty for wrong response from server. 495 // headers_ might be empty for wrong response from server.
494 496
495 return status_line_ + headers_ + header_separator_; 497 return status_line_ + headers_ + header_separator_;
496 } 498 }
497 499
498 } // namespace net 500 } // namespace net
OLDNEW
« no previous file with comments | « trunk/src/net/websockets/websocket_basic_handshake_stream.cc ('k') | trunk/src/remoting/base/rsa_key_pair.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698