OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/http/http_stream_factory_impl.h" | 5 #include "net/http/http_stream_factory_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 HttpStreamRequest::Delegate* delegate, | 98 HttpStreamRequest::Delegate* delegate, |
99 WebSocketHandshakeStreamBase::CreateHelper* | 99 WebSocketHandshakeStreamBase::CreateHelper* |
100 websocket_handshake_stream_create_helper, | 100 websocket_handshake_stream_create_helper, |
101 const BoundNetLog& net_log) { | 101 const BoundNetLog& net_log) { |
102 Request* request = new Request(request_info.url, | 102 Request* request = new Request(request_info.url, |
103 this, | 103 this, |
104 delegate, | 104 delegate, |
105 websocket_handshake_stream_create_helper, | 105 websocket_handshake_stream_create_helper, |
106 net_log); | 106 net_log); |
107 | 107 |
| 108 // TODO(bnc): Get rid of |alternate_url|. |
108 GURL alternate_url; | 109 GURL alternate_url; |
109 AlternateProtocolInfo alternate = | 110 AlternativeService alternative_service = |
110 GetAlternateProtocolRequestFor(request_info.url, &alternate_url); | 111 GetAlternativeServiceRequestFor(request_info.url, &alternate_url); |
111 Job* alternate_job = NULL; | 112 Job* alternate_job = NULL; |
112 if (alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { | 113 if (alternative_service.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { |
113 // Never share connection with other jobs for FTP requests. | 114 // Never share connection with other jobs for FTP requests. |
114 DCHECK(!request_info.url.SchemeIs("ftp")); | 115 DCHECK(!request_info.url.SchemeIs("ftp")); |
115 | 116 |
116 HttpRequestInfo alternate_request_info = request_info; | 117 HttpRequestInfo alternate_request_info = request_info; |
117 alternate_request_info.url = alternate_url; | 118 alternate_request_info.url = alternate_url; |
118 alternate_job = | 119 alternate_job = |
119 new Job(this, session_, alternate_request_info, priority, | 120 new Job(this, session_, alternate_request_info, priority, |
120 server_ssl_config, proxy_ssl_config, net_log.net_log()); | 121 server_ssl_config, proxy_ssl_config, net_log.net_log()); |
121 request->AttachJob(alternate_job); | 122 request->AttachJob(alternate_job); |
122 alternate_job->MarkAsAlternate(request_info.url, alternate); | 123 alternate_job->MarkAsAlternate(request_info.url, alternative_service); |
123 } | 124 } |
124 | 125 |
125 Job* job = new Job(this, session_, request_info, priority, | 126 Job* job = new Job(this, session_, request_info, priority, |
126 server_ssl_config, proxy_ssl_config, net_log.net_log()); | 127 server_ssl_config, proxy_ssl_config, net_log.net_log()); |
127 request->AttachJob(job); | 128 request->AttachJob(job); |
128 if (alternate_job) { | 129 if (alternate_job) { |
129 // Never share connection with other jobs for FTP requests. | 130 // Never share connection with other jobs for FTP requests. |
130 DCHECK(!request_info.url.SchemeIs("ftp")); | 131 DCHECK(!request_info.url.SchemeIs("ftp")); |
131 | 132 |
132 job->WaitFor(alternate_job); | 133 job->WaitFor(alternate_job); |
(...skipping 10 matching lines...) Expand all Loading... |
143 } | 144 } |
144 | 145 |
145 void HttpStreamFactoryImpl::PreconnectStreams( | 146 void HttpStreamFactoryImpl::PreconnectStreams( |
146 int num_streams, | 147 int num_streams, |
147 const HttpRequestInfo& request_info, | 148 const HttpRequestInfo& request_info, |
148 RequestPriority priority, | 149 RequestPriority priority, |
149 const SSLConfig& server_ssl_config, | 150 const SSLConfig& server_ssl_config, |
150 const SSLConfig& proxy_ssl_config) { | 151 const SSLConfig& proxy_ssl_config) { |
151 DCHECK(!for_websockets_); | 152 DCHECK(!for_websockets_); |
152 GURL alternate_url; | 153 GURL alternate_url; |
153 AlternateProtocolInfo alternate = | 154 AlternativeService alternative_service = |
154 GetAlternateProtocolRequestFor(request_info.url, &alternate_url); | 155 GetAlternativeServiceRequestFor(request_info.url, &alternate_url); |
155 Job* job = NULL; | 156 Job* job = NULL; |
156 if (alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { | 157 if (alternative_service.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { |
157 HttpRequestInfo alternate_request_info = request_info; | 158 HttpRequestInfo alternate_request_info = request_info; |
158 alternate_request_info.url = alternate_url; | 159 alternate_request_info.url = alternate_url; |
159 job = new Job(this, session_, alternate_request_info, priority, | 160 job = new Job(this, session_, alternate_request_info, priority, |
160 server_ssl_config, proxy_ssl_config, session_->net_log()); | 161 server_ssl_config, proxy_ssl_config, session_->net_log()); |
161 job->MarkAsAlternate(request_info.url, alternate); | 162 job->MarkAsAlternate(request_info.url, alternative_service); |
162 } else { | 163 } else { |
163 job = new Job(this, session_, request_info, priority, | 164 job = new Job(this, session_, request_info, priority, |
164 server_ssl_config, proxy_ssl_config, session_->net_log()); | 165 server_ssl_config, proxy_ssl_config, session_->net_log()); |
165 } | 166 } |
166 preconnect_job_set_.insert(job); | 167 preconnect_job_set_.insert(job); |
167 job->Preconnect(num_streams); | 168 job->Preconnect(num_streams); |
168 } | 169 } |
169 | 170 |
170 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const { | 171 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const { |
171 return session_->params().host_mapping_rules; | 172 return session_->params().host_mapping_rules; |
172 } | 173 } |
173 | 174 |
174 AlternateProtocolInfo HttpStreamFactoryImpl::GetAlternateProtocolRequestFor( | 175 AlternativeService HttpStreamFactoryImpl::GetAlternativeServiceRequestFor( |
175 const GURL& original_url, | 176 const GURL& original_url, |
176 GURL* alternate_url) { | 177 GURL* alternate_url) { |
177 const AlternateProtocolInfo kNoAlternateProtocol; | 178 const AlternativeService kNoAlternativeService; |
178 | 179 |
179 if (!session_->params().use_alternate_protocols) | 180 if (!session_->params().use_alternate_protocols) |
180 return kNoAlternateProtocol; | 181 return kNoAlternativeService; |
181 | 182 |
182 if (original_url.SchemeIs("ftp")) | 183 if (original_url.SchemeIs("ftp")) |
183 return kNoAlternateProtocol; | 184 return kNoAlternativeService; |
184 | 185 |
185 HostPortPair origin = HostPortPair::FromURL(original_url); | 186 HostPortPair origin = HostPortPair::FromURL(original_url); |
186 HttpServerProperties& http_server_properties = | 187 HttpServerProperties& http_server_properties = |
187 *session_->http_server_properties(); | 188 *session_->http_server_properties(); |
188 const AlternateProtocolInfo alternate = | 189 const AlternateProtocolInfo alternate = |
189 http_server_properties.GetAlternateProtocol(origin); | 190 http_server_properties.GetAlternateProtocol(origin); |
190 | 191 |
191 if (alternate.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) | 192 if (alternate.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) |
192 return kNoAlternateProtocol; | 193 return kNoAlternativeService; |
193 const AlternativeService alternative_service(alternate.protocol, | 194 const AlternativeService alternative_service(alternate.protocol, |
194 origin.host(), alternate.port); | 195 origin.host(), alternate.port); |
195 if (http_server_properties.IsAlternativeServiceBroken(alternative_service)) { | 196 if (http_server_properties.IsAlternativeServiceBroken(alternative_service)) { |
196 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN); | 197 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN); |
197 return kNoAlternateProtocol; | 198 return kNoAlternativeService; |
198 } | 199 } |
199 if (!IsAlternateProtocolValid(alternate.protocol)) { | 200 if (!IsAlternateProtocolValid(alternate.protocol)) { |
200 NOTREACHED(); | 201 NOTREACHED(); |
201 return kNoAlternateProtocol; | 202 return kNoAlternativeService; |
202 } | 203 } |
203 | 204 |
204 // Some shared unix systems may have user home directories (like | 205 // Some shared unix systems may have user home directories (like |
205 // http://foo.com/~mike) which allow users to emit headers. This is a bad | 206 // http://foo.com/~mike) which allow users to emit headers. This is a bad |
206 // idea already, but with Alternate-Protocol, it provides the ability for a | 207 // idea already, but with Alternate-Protocol, it provides the ability for a |
207 // single user on a multi-user system to hijack the alternate protocol. | 208 // single user on a multi-user system to hijack the alternate protocol. |
208 // These systems also enforce ports <1024 as restricted ports. So don't | 209 // These systems also enforce ports <1024 as restricted ports. So don't |
209 // allow protocol upgrades to user-controllable ports. | 210 // allow protocol upgrades to user-controllable ports. |
210 const int kUnrestrictedPort = 1024; | 211 const int kUnrestrictedPort = 1024; |
211 if (!session_->params().enable_user_alternate_protocol_ports && | 212 if (!session_->params().enable_user_alternate_protocol_ports && |
212 (alternate.port >= kUnrestrictedPort && | 213 (alternate.port >= kUnrestrictedPort && |
213 origin.port() < kUnrestrictedPort)) | 214 origin.port() < kUnrestrictedPort)) |
214 return kNoAlternateProtocol; | 215 return kNoAlternativeService; |
215 | 216 |
216 origin.set_port(alternate.port); | 217 origin.set_port(alternate.port); |
217 if (alternate.protocol >= NPN_SPDY_MINIMUM_VERSION && | 218 if (alternate.protocol >= NPN_SPDY_MINIMUM_VERSION && |
218 alternate.protocol <= NPN_SPDY_MAXIMUM_VERSION) { | 219 alternate.protocol <= NPN_SPDY_MAXIMUM_VERSION) { |
219 if (!HttpStreamFactory::spdy_enabled()) | 220 if (!HttpStreamFactory::spdy_enabled()) |
220 return kNoAlternateProtocol; | 221 return kNoAlternativeService; |
221 | 222 |
222 if (session_->HasSpdyExclusion(origin)) | 223 if (session_->HasSpdyExclusion(origin)) |
223 return kNoAlternateProtocol; | 224 return kNoAlternativeService; |
224 | 225 |
225 *alternate_url = UpgradeUrlToHttps(original_url, alternate.port); | 226 *alternate_url = UpgradeUrlToHttps(original_url, alternate.port); |
226 } else { | 227 } else { |
227 DCHECK_EQ(QUIC, alternate.protocol); | 228 DCHECK_EQ(QUIC, alternate.protocol); |
228 if (!session_->params().enable_quic) | 229 if (!session_->params().enable_quic) |
229 return kNoAlternateProtocol; | 230 return kNoAlternativeService; |
230 | 231 |
231 // TODO(rch): Figure out how to make QUIC iteract with PAC | 232 // TODO(rch): Figure out how to make QUIC iteract with PAC |
232 // scripts. By not re-writing the URL, we will query the PAC script | 233 // scripts. By not re-writing the URL, we will query the PAC script |
233 // for the proxy to use to reach the original URL via TCP. But | 234 // for the proxy to use to reach the original URL via TCP. But |
234 // the alternate request will be going via UDP to a different port. | 235 // the alternate request will be going via UDP to a different port. |
235 *alternate_url = original_url; | 236 *alternate_url = original_url; |
236 } | 237 } |
237 return alternate; | 238 return AlternativeService(alternate.protocol, origin.host(), alternate.port); |
238 } | 239 } |
239 | 240 |
240 void HttpStreamFactoryImpl::OrphanJob(Job* job, const Request* request) { | 241 void HttpStreamFactoryImpl::OrphanJob(Job* job, const Request* request) { |
241 DCHECK(ContainsKey(request_map_, job)); | 242 DCHECK(ContainsKey(request_map_, job)); |
242 DCHECK_EQ(request_map_[job], request); | 243 DCHECK_EQ(request_map_[job], request); |
243 DCHECK(!ContainsKey(orphaned_job_set_, job)); | 244 DCHECK(!ContainsKey(orphaned_job_set_, job)); |
244 | 245 |
245 request_map_.erase(job); | 246 request_map_.erase(job); |
246 | 247 |
247 orphaned_job_set_.insert(job); | 248 orphaned_job_set_.insert(job); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 delete job; | 297 delete job; |
297 } | 298 } |
298 | 299 |
299 void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) { | 300 void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) { |
300 preconnect_job_set_.erase(job); | 301 preconnect_job_set_.erase(job); |
301 delete job; | 302 delete job; |
302 OnPreconnectsCompleteInternal(); | 303 OnPreconnectsCompleteInternal(); |
303 } | 304 } |
304 | 305 |
305 } // namespace net | 306 } // namespace net |
OLD | NEW |