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_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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 139 |
140 void Delegate::OnReadCompleted(URLRequest* request, int bytes_read) { | 140 void Delegate::OnReadCompleted(URLRequest* request, int bytes_read) { |
141 NOTREACHED(); | 141 NOTREACHED(); |
142 } | 142 } |
143 | 143 |
144 // Internal implementation of CreateAndConnectStream and | 144 // Internal implementation of CreateAndConnectStream and |
145 // CreateAndConnectStreamForTesting. | 145 // CreateAndConnectStreamForTesting. |
146 scoped_ptr<WebSocketStreamRequest> CreateAndConnectStreamWithCreateHelper( | 146 scoped_ptr<WebSocketStreamRequest> CreateAndConnectStreamWithCreateHelper( |
147 const GURL& socket_url, | 147 const GURL& socket_url, |
148 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper, | 148 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper, |
149 const GURL& origin, | 149 const GURL& origin_url, |
150 URLRequestContext* url_request_context, | 150 URLRequestContext* url_request_context, |
151 const BoundNetLog& net_log, | 151 const BoundNetLog& net_log, |
152 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { | 152 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { |
153 scoped_ptr<StreamRequestImpl> request( | 153 scoped_ptr<StreamRequestImpl> request( |
154 new StreamRequestImpl(socket_url, | 154 new StreamRequestImpl(socket_url, |
155 url_request_context, | 155 url_request_context, |
156 connect_delegate.Pass(), | 156 connect_delegate.Pass(), |
157 create_helper.get())); | 157 create_helper.get())); |
158 HttpRequestHeaders headers; | 158 HttpRequestHeaders headers; |
| 159 std::string origin; |
| 160 if (origin_url.is_valid()) { |
| 161 // GURL::spec() adds a slash at the end of an origin, |
| 162 // so we construct the origin string representation by hand. |
| 163 origin = origin_url.scheme() + "://" + origin_url.host(); |
| 164 if (origin_url.has_port()) |
| 165 origin += ":" + origin_url.port(); |
| 166 } else { |
| 167 origin = "null"; |
| 168 } |
| 169 |
159 headers.SetHeader(websockets::kUpgrade, websockets::kWebSocketLowercase); | 170 headers.SetHeader(websockets::kUpgrade, websockets::kWebSocketLowercase); |
160 headers.SetHeader(HttpRequestHeaders::kConnection, websockets::kUpgrade); | 171 headers.SetHeader(HttpRequestHeaders::kConnection, websockets::kUpgrade); |
161 headers.SetHeader(HttpRequestHeaders::kOrigin, origin.spec()); | 172 headers.SetHeader(HttpRequestHeaders::kOrigin, origin); |
162 // TODO(ricea): Move the version number to websocket_handshake_constants.h | 173 // TODO(ricea): Move the version number to websocket_handshake_constants.h |
163 headers.SetHeader(websockets::kSecWebSocketVersion, | 174 headers.SetHeader(websockets::kSecWebSocketVersion, |
164 websockets::kSupportedVersion); | 175 websockets::kSupportedVersion); |
165 request->url_request()->SetExtraRequestHeaders(headers); | 176 request->url_request()->SetExtraRequestHeaders(headers); |
166 request->url_request()->SetUserData( | 177 request->url_request()->SetUserData( |
167 WebSocketHandshakeStreamBase::CreateHelper::DataKey(), | 178 WebSocketHandshakeStreamBase::CreateHelper::DataKey(), |
168 create_helper.release()); | 179 create_helper.release()); |
169 request->url_request()->SetLoadFlags(LOAD_DISABLE_CACHE | | 180 request->url_request()->SetLoadFlags(LOAD_DISABLE_CACHE | |
170 LOAD_BYPASS_CACHE | | 181 LOAD_BYPASS_CACHE | |
171 LOAD_DO_NOT_PROMPT_FOR_LOGIN); | 182 LOAD_DO_NOT_PROMPT_FOR_LOGIN); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { | 221 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { |
211 return CreateAndConnectStreamWithCreateHelper(socket_url, | 222 return CreateAndConnectStreamWithCreateHelper(socket_url, |
212 create_helper.Pass(), | 223 create_helper.Pass(), |
213 origin, | 224 origin, |
214 url_request_context, | 225 url_request_context, |
215 net_log, | 226 net_log, |
216 connect_delegate.Pass()); | 227 connect_delegate.Pass()); |
217 } | 228 } |
218 | 229 |
219 } // namespace net | 230 } // namespace net |
OLD | NEW |