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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 GURL alternate_url; | 109 GURL alternate_url; |
110 AlternateProtocolInfo alternate = | 110 AlternateProtocolInfo alternate = |
111 GetAlternateProtocolRequestFor(request_info.url, &alternate_url); | 111 GetAlternateProtocolRequestFor(request_info.url, &alternate_url); |
112 Job* alternate_job = NULL; | 112 Job* alternate_job = NULL; |
113 if (alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { | 113 if (alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { |
114 // Never share connection with other jobs for FTP requests. | 114 // Never share connection with other jobs for FTP requests. |
115 DCHECK(!request_info.url.SchemeIs("ftp")); | 115 DCHECK(!request_info.url.SchemeIs("ftp")); |
116 | 116 |
117 HttpRequestInfo alternate_request_info = request_info; | 117 HttpRequestInfo alternate_request_info = request_info; |
118 alternate_request_info.url = alternate_url; | 118 alternate_request_info.url = alternate_url; |
119 alternate_job = | 119 alternate_job = new Job(this, session_, alternate_request_info, priority, |
120 new Job(this, session_, alternate_request_info, priority, | 120 server_ssl_config, proxy_ssl_config, |
121 server_ssl_config, proxy_ssl_config, net_log.net_log()); | 121 net_log.net_log(), alternate); |
122 request->AttachJob(alternate_job); | 122 request->AttachJob(alternate_job); |
123 alternate_job->MarkAsAlternate(request_info.url, alternate); | 123 alternate_job->MarkAsAlternate(request_info.url); |
124 } | 124 } |
125 | 125 |
126 Job* job = new Job(this, session_, request_info, priority, | 126 Job* job = new Job(this, session_, request_info, priority, server_ssl_config, |
127 server_ssl_config, proxy_ssl_config, net_log.net_log()); | 127 proxy_ssl_config, net_log.net_log(), alternate); |
128 request->AttachJob(job); | 128 request->AttachJob(job); |
129 if (alternate_job) { | 129 if (alternate_job) { |
130 // Never share connection with other jobs for FTP requests. | 130 // Never share connection with other jobs for FTP requests. |
131 DCHECK(!request_info.url.SchemeIs("ftp")); | 131 DCHECK(!request_info.url.SchemeIs("ftp")); |
132 | 132 |
133 job->WaitFor(alternate_job); | 133 job->WaitFor(alternate_job); |
134 // Make sure to wait until we call WaitFor(), before starting | 134 // Make sure to wait until we call WaitFor(), before starting |
135 // |alternate_job|, otherwise |alternate_job| will not notify |job| | 135 // |alternate_job|, otherwise |alternate_job| will not notify |job| |
136 // appropriately. | 136 // appropriately. |
137 alternate_job->Start(request); | 137 alternate_job->Start(request); |
(...skipping 13 matching lines...) Expand all Loading... |
151 const SSLConfig& proxy_ssl_config) { | 151 const SSLConfig& proxy_ssl_config) { |
152 DCHECK(!for_websockets_); | 152 DCHECK(!for_websockets_); |
153 GURL alternate_url; | 153 GURL alternate_url; |
154 AlternateProtocolInfo alternate = | 154 AlternateProtocolInfo alternate = |
155 GetAlternateProtocolRequestFor(request_info.url, &alternate_url); | 155 GetAlternateProtocolRequestFor(request_info.url, &alternate_url); |
156 Job* job = NULL; | 156 Job* job = NULL; |
157 if (alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { | 157 if (alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { |
158 HttpRequestInfo alternate_request_info = request_info; | 158 HttpRequestInfo alternate_request_info = request_info; |
159 alternate_request_info.url = alternate_url; | 159 alternate_request_info.url = alternate_url; |
160 job = new Job(this, session_, alternate_request_info, priority, | 160 job = new Job(this, session_, alternate_request_info, priority, |
161 server_ssl_config, proxy_ssl_config, session_->net_log()); | 161 server_ssl_config, proxy_ssl_config, session_->net_log(), |
162 job->MarkAsAlternate(request_info.url, alternate); | 162 alternate); |
| 163 job->MarkAsAlternate(request_info.url); |
163 } else { | 164 } else { |
164 job = new Job(this, session_, request_info, priority, | 165 job = new Job(this, session_, request_info, priority, server_ssl_config, |
165 server_ssl_config, proxy_ssl_config, session_->net_log()); | 166 proxy_ssl_config, session_->net_log(), alternate); |
166 } | 167 } |
167 preconnect_job_set_.insert(job); | 168 preconnect_job_set_.insert(job); |
168 job->Preconnect(num_streams); | 169 job->Preconnect(num_streams); |
169 } | 170 } |
170 | 171 |
171 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const { | 172 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const { |
172 return session_->params().host_mapping_rules; | 173 return session_->params().host_mapping_rules; |
173 } | 174 } |
174 | 175 |
175 AlternateProtocolInfo HttpStreamFactoryImpl::GetAlternateProtocolRequestFor( | 176 AlternateProtocolInfo HttpStreamFactoryImpl::GetAlternateProtocolRequestFor( |
176 const GURL& original_url, | 177 const GURL& original_url, |
177 GURL* alternate_url) { | 178 GURL* alternate_url) { |
178 const AlternateProtocolInfo kNoAlternateProtocol = | 179 const AlternateProtocolInfo kNoAlternateProtocol = |
179 AlternateProtocolInfo(0, UNINITIALIZED_ALTERNATE_PROTOCOL, 0); | 180 AlternateProtocolInfo(0, UNINITIALIZED_ALTERNATE_PROTOCOL, 0); |
180 | 181 |
181 if (!session_->params().use_alternate_protocols) | 182 if (!session_->params().use_alternate_protocols) |
182 return kNoAlternateProtocol; | 183 return kNoAlternateProtocol; |
183 | 184 |
184 if (original_url.SchemeIs("ftp")) | 185 if (original_url.SchemeIs("ftp")) |
185 return kNoAlternateProtocol; | 186 return kNoAlternateProtocol; |
186 | 187 |
187 HostPortPair origin = HostPortPair::FromURL(original_url); | 188 HostPortPair origin = HostPortPair::FromURL(original_url); |
188 | 189 |
189 HttpServerProperties& http_server_properties = | 190 HttpServerProperties& http_server_properties = |
190 *session_->http_server_properties(); | 191 *session_->http_server_properties(); |
191 if (!http_server_properties.HasAlternateProtocol(origin)) | 192 if (!http_server_properties.HasAlternateProtocol(origin)) |
192 return kNoAlternateProtocol; | 193 return kNoAlternateProtocol; |
193 | 194 |
194 AlternateProtocolInfo alternate = | 195 AlternateProtocols alternate_protocols = |
195 http_server_properties.GetAlternateProtocol(origin); | 196 http_server_properties.GetAlternateProtocols(origin); |
196 if (alternate.is_broken) { | 197 for (AlternateProtocols::iterator alternate = alternate_protocols.begin(); |
197 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN); | 198 alternate != alternate_protocols.end(); ++alternate) { |
198 return kNoAlternateProtocol; | 199 if (alternate->is_broken) { |
| 200 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN); |
| 201 continue; |
| 202 } |
| 203 |
| 204 if (!IsAlternateProtocolValid(alternate->protocol)) { |
| 205 NOTREACHED(); |
| 206 continue; |
| 207 } |
| 208 |
| 209 // Some shared unix systems may have user home directories (like |
| 210 // http://foo.com/~mike) which allow users to emit headers. This is a bad |
| 211 // idea already, but with Alternate-Protocol, it provides the ability for a |
| 212 // single user on a multi-user system to hijack the alternate protocol. |
| 213 // These systems also enforce ports <1024 as restricted ports. So don't |
| 214 // allow protocol upgrades to user-controllable ports. |
| 215 const int kUnrestrictedPort = 1024; |
| 216 if (!session_->params().enable_user_alternate_protocol_ports && |
| 217 (alternate->port >= kUnrestrictedPort && |
| 218 origin.port() < kUnrestrictedPort)) |
| 219 continue; |
| 220 |
| 221 origin.set_port(alternate->port); |
| 222 if (alternate->protocol >= NPN_SPDY_MINIMUM_VERSION && |
| 223 alternate->protocol <= NPN_SPDY_MAXIMUM_VERSION) { |
| 224 if (!HttpStreamFactory::spdy_enabled()) |
| 225 continue; |
| 226 |
| 227 if (session_->HasSpdyExclusion(origin)) |
| 228 continue; |
| 229 |
| 230 *alternate_url = UpgradeUrlToHttps(original_url, alternate->port); |
| 231 return *alternate; |
| 232 } else { |
| 233 DCHECK_EQ(QUIC, alternate->protocol); |
| 234 if (!session_->params().enable_quic) |
| 235 continue; |
| 236 |
| 237 // TODO(rch): Figure out how to make QUIC iteract with PAC |
| 238 // scripts. By not re-writing the URL, we will query the PAC script |
| 239 // for the proxy to use to reach the original URL via TCP. But |
| 240 // the alternate request will be going via UDP to a different port. |
| 241 *alternate_url = original_url; |
| 242 return *alternate; |
| 243 } |
199 } | 244 } |
200 | 245 return kNoAlternateProtocol; |
201 if (!IsAlternateProtocolValid(alternate.protocol)) { | |
202 NOTREACHED(); | |
203 return kNoAlternateProtocol; | |
204 } | |
205 | |
206 // Some shared unix systems may have user home directories (like | |
207 // http://foo.com/~mike) which allow users to emit headers. This is a bad | |
208 // idea already, but with Alternate-Protocol, it provides the ability for a | |
209 // single user on a multi-user system to hijack the alternate protocol. | |
210 // These systems also enforce ports <1024 as restricted ports. So don't | |
211 // allow protocol upgrades to user-controllable ports. | |
212 const int kUnrestrictedPort = 1024; | |
213 if (!session_->params().enable_user_alternate_protocol_ports && | |
214 (alternate.port >= kUnrestrictedPort && | |
215 origin.port() < kUnrestrictedPort)) | |
216 return kNoAlternateProtocol; | |
217 | |
218 origin.set_port(alternate.port); | |
219 if (alternate.protocol >= NPN_SPDY_MINIMUM_VERSION && | |
220 alternate.protocol <= NPN_SPDY_MAXIMUM_VERSION) { | |
221 if (!HttpStreamFactory::spdy_enabled()) | |
222 return kNoAlternateProtocol; | |
223 | |
224 if (session_->HasSpdyExclusion(origin)) | |
225 return kNoAlternateProtocol; | |
226 | |
227 *alternate_url = UpgradeUrlToHttps(original_url, alternate.port); | |
228 } else { | |
229 DCHECK_EQ(QUIC, alternate.protocol); | |
230 if (!session_->params().enable_quic) | |
231 return kNoAlternateProtocol; | |
232 | |
233 // TODO(rch): Figure out how to make QUIC iteract with PAC | |
234 // scripts. By not re-writing the URL, we will query the PAC script | |
235 // for the proxy to use to reach the original URL via TCP. But | |
236 // the alternate request will be going via UDP to a different port. | |
237 *alternate_url = original_url; | |
238 } | |
239 return alternate; | |
240 } | 246 } |
241 | 247 |
242 void HttpStreamFactoryImpl::OrphanJob(Job* job, const Request* request) { | 248 void HttpStreamFactoryImpl::OrphanJob(Job* job, const Request* request) { |
243 DCHECK(ContainsKey(request_map_, job)); | 249 DCHECK(ContainsKey(request_map_, job)); |
244 DCHECK_EQ(request_map_[job], request); | 250 DCHECK_EQ(request_map_[job], request); |
245 DCHECK(!ContainsKey(orphaned_job_set_, job)); | 251 DCHECK(!ContainsKey(orphaned_job_set_, job)); |
246 | 252 |
247 request_map_.erase(job); | 253 request_map_.erase(job); |
248 | 254 |
249 orphaned_job_set_.insert(job); | 255 orphaned_job_set_.insert(job); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 delete job; | 304 delete job; |
299 } | 305 } |
300 | 306 |
301 void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) { | 307 void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) { |
302 preconnect_job_set_.erase(job); | 308 preconnect_job_set_.erase(job); |
303 delete job; | 309 delete job; |
304 OnPreconnectsCompleteInternal(); | 310 OnPreconnectsCompleteInternal(); |
305 } | 311 } |
306 | 312 |
307 } // namespace net | 313 } // namespace net |
OLD | NEW |