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

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 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
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 const URLRequestStatus& status = url_request_.status();
78 if (status.status() == URLRequestStatus::CANCELED) {
79 failure_message = "WebSocket opening handshake was canceled";
80 } else if (status.status() == URLRequestStatus::FAILED) {
81 failure_message =
82 std::string("Error in connection establishment: ") +
83 ErrorToString(status.error());
84 }
85 }
86 connect_delegate_->OnFailure(failure_message);
74 } 87 }
75 88
76 private: 89 private:
77 // |delegate_| needs to be declared before |url_request_| so that it gets 90 // |delegate_| needs to be declared before |url_request_| so that it gets
78 // initialised first. 91 // initialised first.
79 scoped_ptr<Delegate> delegate_; 92 scoped_ptr<Delegate> delegate_;
80 93
81 // Deleting the StreamRequestImpl object deletes this URLRequest object, 94 // Deleting the StreamRequestImpl object deletes this URLRequest object,
82 // cancelling the whole connection. 95 // cancelling the whole connection.
83 URLRequest url_request_; 96 URLRequest url_request_;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { 203 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) {
191 return CreateAndConnectStreamWithCreateHelper(socket_url, 204 return CreateAndConnectStreamWithCreateHelper(socket_url,
192 create_helper.Pass(), 205 create_helper.Pass(),
193 origin, 206 origin,
194 url_request_context, 207 url_request_context,
195 net_log, 208 net_log,
196 connect_delegate.Pass()); 209 connect_delegate.Pass());
197 } 210 }
198 211
199 } // namespace net 212 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698