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 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 #include "net/websockets/websocket_handshake_challenge.h" | 43 #include "net/websockets/websocket_handshake_challenge.h" |
44 #include "net/websockets/websocket_handshake_constants.h" | 44 #include "net/websockets/websocket_handshake_constants.h" |
45 #include "net/websockets/websocket_handshake_request_info.h" | 45 #include "net/websockets/websocket_handshake_request_info.h" |
46 #include "net/websockets/websocket_handshake_response_info.h" | 46 #include "net/websockets/websocket_handshake_response_info.h" |
47 #include "net/websockets/websocket_stream.h" | 47 #include "net/websockets/websocket_stream.h" |
48 | 48 |
49 namespace net { | 49 namespace net { |
50 | 50 |
51 namespace { | 51 namespace { |
52 | 52 |
| 53 const char kConnectionErrorStatusLine[] = "HTTP/1.1 503 Connection Error"; |
| 54 |
53 // TODO(yhirano): Remove these functions once http://crbug.com/399535 is fixed. | 55 // TODO(yhirano): Remove these functions once http://crbug.com/399535 is fixed. |
54 NOINLINE void RunCallbackWithOk(const CompletionCallback& callback, | 56 NOINLINE void RunCallbackWithOk(const CompletionCallback& callback, |
55 int result) { | 57 int result) { |
56 DCHECK_EQ(result, OK); | 58 DCHECK_EQ(result, OK); |
57 callback.Run(OK); | 59 callback.Run(OK); |
58 } | 60 } |
59 | 61 |
60 NOINLINE void RunCallbackWithInvalidResponseCausedByRedirect( | 62 NOINLINE void RunCallbackWithInvalidResponseCausedByRedirect( |
61 const CompletionCallback& callback, | 63 const CompletionCallback& callback, |
62 int result) { | 64 int result) { |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 } | 649 } |
648 } else { | 650 } else { |
649 if (rv == ERR_EMPTY_RESPONSE) { | 651 if (rv == ERR_EMPTY_RESPONSE) { |
650 set_failure_message( | 652 set_failure_message( |
651 "Connection closed before receiving a handshake response"); | 653 "Connection closed before receiving a handshake response"); |
652 return rv; | 654 return rv; |
653 } | 655 } |
654 set_failure_message(std::string("Error during WebSocket handshake: ") + | 656 set_failure_message(std::string("Error during WebSocket handshake: ") + |
655 ErrorToString(rv)); | 657 ErrorToString(rv)); |
656 OnFinishOpeningHandshake(); | 658 OnFinishOpeningHandshake(); |
| 659 // Some error codes (for example ERR_CONNECTION_CLOSED) get changed to OK at |
| 660 // higher levels. To prevent an unvalidated connection getting erroneously |
| 661 // upgraded, don't pass through the status code unchanged if it is |
| 662 // HTTP_SWITCHING_PROTOCOLS. |
| 663 if (http_response_info_->headers && |
| 664 http_response_info_->headers->response_code() == |
| 665 HTTP_SWITCHING_PROTOCOLS) { |
| 666 http_response_info_->headers->ReplaceStatusLine( |
| 667 kConnectionErrorStatusLine); |
| 668 } |
657 return rv; | 669 return rv; |
658 } | 670 } |
659 } | 671 } |
660 | 672 |
661 int WebSocketBasicHandshakeStream::ValidateUpgradeResponse( | 673 int WebSocketBasicHandshakeStream::ValidateUpgradeResponse( |
662 const HttpResponseHeaders* headers) { | 674 const HttpResponseHeaders* headers) { |
663 extension_params_.reset(new WebSocketExtensionParams); | 675 extension_params_.reset(new WebSocketExtensionParams); |
664 std::string failure_message; | 676 std::string failure_message; |
665 if (ValidateUpgrade(headers, &failure_message) && | 677 if (ValidateUpgrade(headers, &failure_message) && |
666 ValidateSecWebSocketAccept( | 678 ValidateSecWebSocketAccept( |
(...skipping 13 matching lines...) Expand all Loading... |
680 set_failure_message("Error during WebSocket handshake: " + failure_message); | 692 set_failure_message("Error during WebSocket handshake: " + failure_message); |
681 return ERR_INVALID_RESPONSE; | 693 return ERR_INVALID_RESPONSE; |
682 } | 694 } |
683 | 695 |
684 void WebSocketBasicHandshakeStream::set_failure_message( | 696 void WebSocketBasicHandshakeStream::set_failure_message( |
685 const std::string& failure_message) { | 697 const std::string& failure_message) { |
686 *failure_message_ = failure_message; | 698 *failure_message_ = failure_message; |
687 } | 699 } |
688 | 700 |
689 } // namespace net | 701 } // namespace net |
OLD | NEW |