| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/url_request/url_request.h" | 5 #include "net/url_request/url_request.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
| 10 #include "base/singleton.h" | 10 #include "base/singleton.h" |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 job_->Start(); | 227 job_->Start(); |
| 228 } | 228 } |
| 229 | 229 |
| 230 void URLRequest::Cancel() { | 230 void URLRequest::Cancel() { |
| 231 CancelWithError(net::ERR_ABORTED); | 231 CancelWithError(net::ERR_ABORTED); |
| 232 } | 232 } |
| 233 | 233 |
| 234 void URLRequest::CancelWithError(int os_error) { | 234 void URLRequest::CancelWithError(int os_error) { |
| 235 DCHECK(os_error < 0); | 235 DCHECK(os_error < 0); |
| 236 | 236 |
| 237 // There's nothing to do if we are not waiting on a Job. | |
| 238 if (!is_pending_ || !job_) | |
| 239 return; | |
| 240 | |
| 241 // If the URL request already has an error status, then canceling is a no-op. | 237 // If the URL request already has an error status, then canceling is a no-op. |
| 242 // Plus, we don't want to change the error status once it has been set. | 238 // Plus, we don't want to change the error status once it has been set. |
| 243 if (status_.is_success()) { | 239 if (status_.is_success()) { |
| 244 status_.set_status(URLRequestStatus::CANCELED); | 240 status_.set_status(URLRequestStatus::CANCELED); |
| 245 status_.set_os_error(os_error); | 241 status_.set_os_error(os_error); |
| 246 } | 242 } |
| 247 | 243 |
| 244 // There's nothing to do if we are not waiting on a Job. |
| 245 if (!is_pending_ || !job_) |
| 246 return; |
| 247 |
| 248 job_->Kill(); | 248 job_->Kill(); |
| 249 | 249 |
| 250 // The Job will call our NotifyDone method asynchronously. This is done so | 250 // The Job will call our NotifyDone method asynchronously. This is done so |
| 251 // that the Delegate implementation can call Cancel without having to worry | 251 // that the Delegate implementation can call Cancel without having to worry |
| 252 // about being called recursively. | 252 // about being called recursively. |
| 253 } | 253 } |
| 254 | 254 |
| 255 bool URLRequest::Read(net::IOBuffer* dest, int dest_size, int *bytes_read) { | 255 bool URLRequest::Read(net::IOBuffer* dest, int dest_size, int *bytes_read) { |
| 256 DCHECK(job_); | 256 DCHECK(job_); |
| 257 DCHECK(bytes_read); | 257 DCHECK(bytes_read); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 // NOTE: Even though RFC 2616 says to preserve the request method when | 343 // NOTE: Even though RFC 2616 says to preserve the request method when |
| 344 // following a 302 redirect, normal browsers don't do that. Instead, they | 344 // following a 302 redirect, normal browsers don't do that. Instead, they |
| 345 // all convert a POST into a GET in response to a 302 and so shall we. For | 345 // all convert a POST into a GET in response to a 302 and so shall we. For |
| 346 // 307 redirects, browsers preserve the method. The RFC says to prompt the | 346 // 307 redirects, browsers preserve the method. The RFC says to prompt the |
| 347 // user to confirm the generation of a new POST request, but IE omits this | 347 // user to confirm the generation of a new POST request, but IE omits this |
| 348 // prompt and so shall we. | 348 // prompt and so shall we. |
| 349 strip_post_specific_headers = method_ == "POST"; | 349 strip_post_specific_headers = method_ == "POST"; |
| 350 method_ = "GET"; | 350 method_ = "GET"; |
| 351 } | 351 } |
| 352 url_ = location; | 352 url_ = location; |
| 353 upload_ = 0; | 353 upload_ = NULL; |
| 354 status_ = URLRequestStatus(); | 354 status_ = URLRequestStatus(); |
| 355 --redirect_limit_; | 355 --redirect_limit_; |
| 356 | 356 |
| 357 if (strip_post_specific_headers) { | 357 if (strip_post_specific_headers) { |
| 358 // If being switched from POST to GET, must remove headers that were | 358 // If being switched from POST to GET, must remove headers that were |
| 359 // specific to the POST and don't have meaning in GET. For example | 359 // specific to the POST and don't have meaning in GET. For example |
| 360 // the inclusion of a multipart Content-Type header in GET can cause | 360 // the inclusion of a multipart Content-Type header in GET can cause |
| 361 // problems with some servers: | 361 // problems with some servers: |
| 362 // http://code.google.com/p/chromium/issues/detail?id=843 | 362 // http://code.google.com/p/chromium/issues/detail?id=843 |
| 363 // | 363 // |
| (...skipping 13 matching lines...) Expand all Loading... |
| 377 return net::OK; | 377 return net::OK; |
| 378 } | 378 } |
| 379 | 379 |
| 380 int64 URLRequest::GetExpectedContentSize() const { | 380 int64 URLRequest::GetExpectedContentSize() const { |
| 381 int64 expected_content_size = -1; | 381 int64 expected_content_size = -1; |
| 382 if (job_) | 382 if (job_) |
| 383 expected_content_size = job_->expected_content_size(); | 383 expected_content_size = job_->expected_content_size(); |
| 384 | 384 |
| 385 return expected_content_size; | 385 return expected_content_size; |
| 386 } | 386 } |
| OLD | NEW |