OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this |
2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
3 // LICENSE file. | 3 // LICENSE file. |
4 | 4 |
5 #include "net/proxy/proxy_script_fetcher.h" | 5 #include "net/proxy/proxy_script_fetcher.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
13 #include "net/base/load_flags.h" | 13 #include "net/base/load_flags.h" |
14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 15 #include "net/http/http_response_headers.h" |
15 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
16 | 17 |
17 // TODO(eroman): | 18 // TODO(eroman): |
18 // - Support auth-prompts. | 19 // - Support auth-prompts. |
19 | 20 |
20 namespace net { | 21 namespace net { |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 // The maximum size (in bytes) allowed for a PAC script. Responses exceeding | 25 // The maximum size (in bytes) allowed for a PAC script. Responses exceeding |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 146 |
146 DCHECK(callback); | 147 DCHECK(callback); |
147 DCHECK(bytes); | 148 DCHECK(bytes); |
148 | 149 |
149 cur_request_.reset(new URLRequest(url, this)); | 150 cur_request_.reset(new URLRequest(url, this)); |
150 cur_request_->set_context(url_request_context_); | 151 cur_request_->set_context(url_request_context_); |
151 cur_request_->set_method("GET"); | 152 cur_request_->set_method("GET"); |
152 | 153 |
153 // Make sure that the PAC script is downloaded using a direct connection, | 154 // Make sure that the PAC script is downloaded using a direct connection, |
154 // to avoid circular dependencies (fetching is a part of proxy resolution). | 155 // to avoid circular dependencies (fetching is a part of proxy resolution). |
155 cur_request_->set_load_flags(LOAD_BYPASS_PROXY); | 156 // Also disable the use of the disk cache. The cache is disabled so that if |
| 157 // the user switches networks we don't potentially use the cached response |
| 158 // from old network when we should in fact be re-fetching on the new network. |
| 159 cur_request_->set_load_flags(LOAD_BYPASS_PROXY | LOAD_DISABLE_CACHE); |
156 | 160 |
157 // Save the caller's info for notification on completion. | 161 // Save the caller's info for notification on completion. |
158 callback_ = callback; | 162 callback_ = callback; |
159 result_bytes_ = bytes; | 163 result_bytes_ = bytes; |
160 result_bytes_->clear(); | 164 result_bytes_->clear(); |
161 | 165 |
162 // Post a task to timeout this request if it takes too long. | 166 // Post a task to timeout this request if it takes too long. |
163 cur_request_id_ = ++next_id_; | 167 cur_request_id_ = ++next_id_; |
164 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 168 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
165 task_factory_.NewRunnableMethod(&ProxyScriptFetcherImpl::OnTimeout, | 169 task_factory_.NewRunnableMethod(&ProxyScriptFetcherImpl::OnTimeout, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 if (!request->status().is_success()) { | 211 if (!request->status().is_success()) { |
208 OnResponseCompleted(request); | 212 OnResponseCompleted(request); |
209 return; | 213 return; |
210 } | 214 } |
211 | 215 |
212 // Require HTTP responses to have a success status code. | 216 // Require HTTP responses to have a success status code. |
213 if (request->url().SchemeIs("http") || request->url().SchemeIs("https")) { | 217 if (request->url().SchemeIs("http") || request->url().SchemeIs("https")) { |
214 // NOTE about status codes: We are like Firefox 3 in this respect. | 218 // NOTE about status codes: We are like Firefox 3 in this respect. |
215 // {IE 7, Safari 3, Opera 9.5} do not care about the status code. | 219 // {IE 7, Safari 3, Opera 9.5} do not care about the status code. |
216 if (request->GetResponseCode() != 200) { | 220 if (request->GetResponseCode() != 200) { |
| 221 LOG(INFO) << "Fetched PAC script had (bad) status line: " |
| 222 << request->response_headers()->GetStatusLine(); |
217 result_code_ = ERR_PAC_STATUS_NOT_OK; | 223 result_code_ = ERR_PAC_STATUS_NOT_OK; |
218 request->Cancel(); | 224 request->Cancel(); |
219 return; | 225 return; |
220 } | 226 } |
221 | 227 |
222 // NOTE about mime types: We do not enforce mime types on PAC files. | 228 // NOTE about mime types: We do not enforce mime types on PAC files. |
223 // This is for compatibility with {IE 7, Firefox 3, Opera 9.5}. We will | 229 // This is for compatibility with {IE 7, Firefox 3, Opera 9.5}. We will |
224 // however log mismatches to help with debugging. | 230 // however log mismatches to help with debugging. |
225 if (logging::GetMinLogLevel() <= logging::LOG_INFO) { | 231 std::string mime_type; |
226 std::string mime_type; | 232 cur_request_->GetMimeType(&mime_type); |
227 cur_request_->GetMimeType(&mime_type); | 233 if (!IsPacMimeType(mime_type)) { |
228 if (!IsPacMimeType(mime_type)) { | 234 LOG(INFO) << "Fetched PAC script does not have a proper mime type: " |
229 LOG(INFO) << "Fetched PAC script does not have a proper mime type: " | 235 << mime_type; |
230 << mime_type; | |
231 } | |
232 } | 236 } |
233 } | 237 } |
234 | 238 |
235 ReadBody(request); | 239 ReadBody(request); |
236 } | 240 } |
237 | 241 |
238 void ProxyScriptFetcherImpl::OnReadCompleted(URLRequest* request, | 242 void ProxyScriptFetcherImpl::OnReadCompleted(URLRequest* request, |
239 int num_bytes) { | 243 int num_bytes) { |
240 DCHECK(request == cur_request_.get()); | 244 DCHECK(request == cur_request_.get()); |
241 if (num_bytes > 0) { | 245 if (num_bytes > 0) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 } | 325 } |
322 | 326 |
323 // static | 327 // static |
324 size_t ProxyScriptFetcher::SetSizeConstraintForUnittest(size_t size_bytes) { | 328 size_t ProxyScriptFetcher::SetSizeConstraintForUnittest(size_t size_bytes) { |
325 size_t prev = max_response_bytes; | 329 size_t prev = max_response_bytes; |
326 max_response_bytes = size_bytes; | 330 max_response_bytes = size_bytes; |
327 return prev; | 331 return prev; |
328 } | 332 } |
329 | 333 |
330 } // namespace net | 334 } // namespace net |
OLD | NEW |