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

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

Issue 105833003: Fail WebSocket channel when handshake fails. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 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 | « net/websockets/websocket_stream.h ('k') | 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_stream.h" 5 #include "net/websockets/websocket_stream.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "net/http/http_request_headers.h" 9 #include "net/http/http_request_headers.h"
10 #include "net/http/http_status_code.h" 10 #include "net/http/http_status_code.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // and so terminates the handshake if it is incomplete. 63 // and so terminates the handshake if it is incomplete.
64 virtual ~StreamRequestImpl() {} 64 virtual ~StreamRequestImpl() {}
65 65
66 URLRequest* url_request() { return &url_request_; } 66 URLRequest* url_request() { return &url_request_; }
67 67
68 void PerformUpgrade() { 68 void PerformUpgrade() {
69 connect_delegate_->OnSuccess(create_helper_->stream()->Upgrade()); 69 connect_delegate_->OnSuccess(create_helper_->stream()->Upgrade());
70 } 70 }
71 71
72 void ReportFailure() { 72 void ReportFailure() {
73 connect_delegate_->OnFailure(kWebSocketErrorAbnormalClosure); 73 std::string failure_message;
74 if (create_helper_->stream()) {
75 failure_message = create_helper_->stream()->GetFailureMessage();
76 } else {
77 switch (url_request_.status().status()) {
78 case URLRequestStatus::SUCCESS:
79 case URLRequestStatus::IO_PENDING:
80 break;
81 case URLRequestStatus::CANCELED:
82 failure_message = "WebSocket opening handshake was canceled";
83 break;
84 case URLRequestStatus::FAILED:
85 failure_message =
86 std::string("Error in connection establishment: ") +
87 ErrorToString(url_request_.status().error());
88 break;
89 }
90 }
91 connect_delegate_->OnFailure(failure_message);
74 } 92 }
75 93
76 private: 94 private:
77 // |delegate_| needs to be declared before |url_request_| so that it gets 95 // |delegate_| needs to be declared before |url_request_| so that it gets
78 // initialised first. 96 // initialised first.
79 scoped_ptr<Delegate> delegate_; 97 scoped_ptr<Delegate> delegate_;
80 98
81 // Deleting the StreamRequestImpl object deletes this URLRequest object, 99 // Deleting the StreamRequestImpl object deletes this URLRequest object,
82 // cancelling the whole connection. 100 // cancelling the whole connection.
83 URLRequest url_request_; 101 URLRequest url_request_;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { 208 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) {
191 return CreateAndConnectStreamWithCreateHelper(socket_url, 209 return CreateAndConnectStreamWithCreateHelper(socket_url,
192 create_helper.Pass(), 210 create_helper.Pass(),
193 origin, 211 origin,
194 url_request_context, 212 url_request_context,
195 net_log, 213 net_log,
196 connect_delegate.Pass()); 214 connect_delegate.Pass());
197 } 215 }
198 216
199 } // namespace net 217 } // namespace net
OLDNEW
« no previous file with comments | « net/websockets/websocket_stream.h ('k') | net/websockets/websocket_stream_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698