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

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

Issue 152483003: [WebSocket] Add Cache-Control to the request header. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: status code => response code Created 6 years, 10 months 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 | « no previous file | net/websockets/websocket_handshake_stream_create_helper_test.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 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 WebSocketExtensionParams* params) { 227 WebSocketExtensionParams* params) {
228 static const char kClientPrefix[] = "client_"; 228 static const char kClientPrefix[] = "client_";
229 static const char kServerPrefix[] = "server_"; 229 static const char kServerPrefix[] = "server_";
230 static const char kNoContextTakeover[] = "no_context_takeover"; 230 static const char kNoContextTakeover[] = "no_context_takeover";
231 static const char kMaxWindowBits[] = "max_window_bits"; 231 static const char kMaxWindowBits[] = "max_window_bits";
232 const size_t kPrefixLen = arraysize(kClientPrefix) - 1; 232 const size_t kPrefixLen = arraysize(kClientPrefix) - 1;
233 COMPILE_ASSERT(kPrefixLen == arraysize(kServerPrefix) - 1, 233 COMPILE_ASSERT(kPrefixLen == arraysize(kServerPrefix) - 1,
234 the_strings_server_and_client_must_be_the_same_length); 234 the_strings_server_and_client_must_be_the_same_length);
235 typedef std::vector<WebSocketExtension::Parameter> ParameterVector; 235 typedef std::vector<WebSocketExtension::Parameter> ParameterVector;
236 236
237 DCHECK(extension.name() == "permessage-deflate"); 237 DCHECK_EQ("permessage-deflate", extension.name());
238 const ParameterVector& parameters = extension.parameters(); 238 const ParameterVector& parameters = extension.parameters();
239 std::set<std::string> seen_names; 239 std::set<std::string> seen_names;
240 for (ParameterVector::const_iterator it = parameters.begin(); 240 for (ParameterVector::const_iterator it = parameters.begin();
241 it != parameters.end(); ++it) { 241 it != parameters.end(); ++it) {
242 const std::string& name = it->name(); 242 const std::string& name = it->name();
243 if (seen_names.count(name) != 0) { 243 if (seen_names.count(name) != 0) {
244 *failure_message = 244 *failure_message =
245 "Received duplicate permessage-deflate extension parameter " + name; 245 "Received duplicate permessage-deflate extension parameter " + name;
246 return false; 246 return false;
247 } 247 }
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 handshake_challenge_for_testing_.reset(new std::string(key)); 519 handshake_challenge_for_testing_.reset(new std::string(key));
520 } 520 }
521 521
522 std::string WebSocketBasicHandshakeStream::GetFailureMessage() const { 522 std::string WebSocketBasicHandshakeStream::GetFailureMessage() const {
523 return failure_message_; 523 return failure_message_;
524 } 524 }
525 525
526 void WebSocketBasicHandshakeStream::ReadResponseHeadersCallback( 526 void WebSocketBasicHandshakeStream::ReadResponseHeadersCallback(
527 const CompletionCallback& callback, 527 const CompletionCallback& callback,
528 int result) { 528 int result) {
529 if (result == OK) 529 if (result == OK) {
530 result = ValidateResponse(); 530 result = ValidateResponse();
531 else 531 } else {
532 std::string message = "Unknown failure";
533 const scoped_refptr<HttpResponseHeaders>& headers =
534 http_response_info_->headers;
535 if (headers) {
536 message = base::StringPrintf("Unexpected response code: %d",
537 headers->response_code());
538 }
539 failure_message_ = "Error during WebSocket handshake: " + message;
532 OnFinishOpeningHandshake(); 540 OnFinishOpeningHandshake();
Adam Rice 2014/02/03 08:43:52 OnFinishOpeningHandshake() is also called at line
yhirano 2014/02/03 09:32:52 Done in ValidateResponse. HttpStreamParser return
Adam Rice 2014/02/04 03:52:46 In my tests, HttpStreamParser returns a positive v
yhirano 2014/02/04 04:15:50 Done.
541 }
533 callback.Run(result); 542 callback.Run(result);
534 } 543 }
535 544
536 void WebSocketBasicHandshakeStream::OnFinishOpeningHandshake() { 545 void WebSocketBasicHandshakeStream::OnFinishOpeningHandshake() {
537 DCHECK(connect_delegate_); 546 DCHECK(connect_delegate_);
538 DCHECK(http_response_info_); 547 DCHECK(http_response_info_);
539 scoped_refptr<HttpResponseHeaders> headers = http_response_info_->headers; 548 scoped_refptr<HttpResponseHeaders> headers = http_response_info_->headers;
540 scoped_ptr<WebSocketHandshakeResponseInfo> response( 549 scoped_ptr<WebSocketHandshakeResponseInfo> response(
541 new WebSocketHandshakeResponseInfo(url_, 550 new WebSocketHandshakeResponseInfo(url_,
542 headers->response_code(), 551 headers->response_code(),
(...skipping 14 matching lines...) Expand all
557 return ValidateUpgradeResponse(headers); 566 return ValidateUpgradeResponse(headers);
558 567
559 // We need to pass these through for authentication to work. 568 // We need to pass these through for authentication to work.
560 case HTTP_UNAUTHORIZED: 569 case HTTP_UNAUTHORIZED:
561 case HTTP_PROXY_AUTHENTICATION_REQUIRED: 570 case HTTP_PROXY_AUTHENTICATION_REQUIRED:
562 return OK; 571 return OK;
563 572
564 // Other status codes are potentially risky (see the warnings in the 573 // Other status codes are potentially risky (see the warnings in the
565 // WHATWG WebSocket API spec) and so are dropped by default. 574 // WHATWG WebSocket API spec) and so are dropped by default.
566 default: 575 default:
567 failure_message_ = base::StringPrintf("Unexpected status code: %d", 576 failure_message_ = base::StringPrintf("Unexpected response code: %d",
568 headers->response_code()); 577 headers->response_code());
569 OnFinishOpeningHandshake(); 578 OnFinishOpeningHandshake();
570 return ERR_INVALID_RESPONSE; 579 return ERR_INVALID_RESPONSE;
571 } 580 }
572 } 581 }
573 582
574 int WebSocketBasicHandshakeStream::ValidateUpgradeResponse( 583 int WebSocketBasicHandshakeStream::ValidateUpgradeResponse(
575 const scoped_refptr<HttpResponseHeaders>& headers) { 584 const scoped_refptr<HttpResponseHeaders>& headers) {
576 extension_params_.reset(new WebSocketExtensionParams); 585 extension_params_.reset(new WebSocketExtensionParams);
577 if (ValidateUpgrade(headers.get(), &failure_message_) && 586 if (ValidateUpgrade(headers.get(), &failure_message_) &&
(...skipping 10 matching lines...) Expand all
588 &extensions_, 597 &extensions_,
589 &failure_message_, 598 &failure_message_,
590 extension_params_.get())) { 599 extension_params_.get())) {
591 return OK; 600 return OK;
592 } 601 }
593 failure_message_ = "Error during WebSocket handshake: " + failure_message_; 602 failure_message_ = "Error during WebSocket handshake: " + failure_message_;
594 return ERR_INVALID_RESPONSE; 603 return ERR_INVALID_RESPONSE;
595 } 604 }
596 605
597 } // namespace net 606 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/websockets/websocket_handshake_stream_create_helper_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698