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

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

Issue 173523004: Use a better error message for bad status lines. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Update WebSocketStreamCreateTest.MalformedResponse 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_stream_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 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 return ValidateUpgradeResponse(headers); 558 return ValidateUpgradeResponse(headers);
559 559
560 // We need to pass these through for authentication to work. 560 // We need to pass these through for authentication to work.
561 case HTTP_UNAUTHORIZED: 561 case HTTP_UNAUTHORIZED:
562 case HTTP_PROXY_AUTHENTICATION_REQUIRED: 562 case HTTP_PROXY_AUTHENTICATION_REQUIRED:
563 return OK; 563 return OK;
564 564
565 // Other status codes are potentially risky (see the warnings in the 565 // Other status codes are potentially risky (see the warnings in the
566 // WHATWG WebSocket API spec) and so are dropped by default. 566 // WHATWG WebSocket API spec) and so are dropped by default.
567 default: 567 default:
568 failure_message_ = base::StringPrintf( 568 // A WebSocket server cannot be using HTTP/0.9, so if we see version
569 "Error during WebSocket handshake: Unexpected response code: %d", 569 // 0.9, it means the response was garbage.
570 headers->response_code()); 570 // Reporting "Unexpected response code: 200" in this case is not
571 // helpful, so use a different error message.
572 if (headers->GetHttpVersion() == HttpVersion(0, 9)) {
573 failure_message_ =
574 "Error during WebSocket handshake: Invalid status line";
575 } else {
576 failure_message_ = base::StringPrintf(
577 "Error during WebSocket handshake: Unexpected response code: %d",
578 headers->response_code());
579 }
571 OnFinishOpeningHandshake(); 580 OnFinishOpeningHandshake();
572 return ERR_INVALID_RESPONSE; 581 return ERR_INVALID_RESPONSE;
573 } 582 }
574 } else { 583 } else {
575 if (rv == ERR_EMPTY_RESPONSE) { 584 if (rv == ERR_EMPTY_RESPONSE) {
576 failure_message_ = 585 failure_message_ =
577 "Connection closed before receiving a handshake response"; 586 "Connection closed before receiving a handshake response";
578 return rv; 587 return rv;
579 } 588 }
580 failure_message_ = 589 failure_message_ =
(...skipping 20 matching lines...) Expand all
601 &extensions_, 610 &extensions_,
602 &failure_message_, 611 &failure_message_,
603 extension_params_.get())) { 612 extension_params_.get())) {
604 return OK; 613 return OK;
605 } 614 }
606 failure_message_ = "Error during WebSocket handshake: " + failure_message_; 615 failure_message_ = "Error during WebSocket handshake: " + failure_message_;
607 return ERR_INVALID_RESPONSE; 616 return ERR_INVALID_RESPONSE;
608 } 617 }
609 618
610 } // namespace net 619 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/websockets/websocket_stream_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698