| 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/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/process_util.h" | 8 #include "base/process_util.h" |
| 9 #include "base/singleton.h" | 9 #include "base/singleton.h" |
| 10 #include "base/stats_counters.h" | 10 #include "base/stats_counters.h" |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 DCHECK(!is_pending_); | 243 DCHECK(!is_pending_); |
| 244 DCHECK(!job_); | 244 DCHECK(!job_); |
| 245 | 245 |
| 246 job_ = GetJobManager()->CreateJob(this); | 246 job_ = GetJobManager()->CreateJob(this); |
| 247 job_->SetExtraRequestHeaders(extra_request_headers_); | 247 job_->SetExtraRequestHeaders(extra_request_headers_); |
| 248 | 248 |
| 249 if (upload_.get()) | 249 if (upload_.get()) |
| 250 job_->SetUpload(upload_.get()); | 250 job_->SetUpload(upload_.get()); |
| 251 | 251 |
| 252 is_pending_ = true; | 252 is_pending_ = true; |
| 253 |
| 253 response_info_.request_time = Time::Now(); | 254 response_info_.request_time = Time::Now(); |
| 254 response_info_.was_cached = false; | 255 response_info_.was_cached = false; |
| 255 | 256 |
| 256 // Don't allow errors to be sent from within Start(). | 257 // Don't allow errors to be sent from within Start(). |
| 257 // TODO(brettw) this may cause NotifyDone to be sent synchronously, | 258 // TODO(brettw) this may cause NotifyDone to be sent synchronously, |
| 258 // we probably don't want this: they should be sent asynchronously so | 259 // we probably don't want this: they should be sent asynchronously so |
| 259 // the caller does not get reentered. | 260 // the caller does not get reentered. |
| 260 job_->Start(); | 261 job_->Start(); |
| 261 } | 262 } |
| 262 | 263 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 | 313 |
| 313 // Once the request fails or is cancelled, read will just return 0 bytes | 314 // Once the request fails or is cancelled, read will just return 0 bytes |
| 314 // to indicate end of stream. | 315 // to indicate end of stream. |
| 315 if (!status_.is_success()) { | 316 if (!status_.is_success()) { |
| 316 return true; | 317 return true; |
| 317 } | 318 } |
| 318 | 319 |
| 319 return job_->Read(dest, dest_size, bytes_read); | 320 return job_->Read(dest, dest_size, bytes_read); |
| 320 } | 321 } |
| 321 | 322 |
| 323 void URLRequest::FollowDeferredRedirect() { |
| 324 DCHECK(job_); |
| 325 |
| 326 job_->FollowDeferredRedirect(); |
| 327 } |
| 328 |
| 322 void URLRequest::SetAuth(const wstring& username, const wstring& password) { | 329 void URLRequest::SetAuth(const wstring& username, const wstring& password) { |
| 323 DCHECK(job_); | 330 DCHECK(job_); |
| 324 DCHECK(job_->NeedsAuth()); | 331 DCHECK(job_->NeedsAuth()); |
| 325 | 332 |
| 326 job_->SetAuth(username, password); | 333 job_->SetAuth(username, password); |
| 327 } | 334 } |
| 328 | 335 |
| 329 void URLRequest::CancelAuth() { | 336 void URLRequest::CancelAuth() { |
| 330 DCHECK(job_); | 337 DCHECK(job_); |
| 331 DCHECK(job_->NeedsAuth()); | 338 DCHECK(job_->NeedsAuth()); |
| 332 | 339 |
| 333 job_->CancelAuth(); | 340 job_->CancelAuth(); |
| 334 } | 341 } |
| 335 | 342 |
| 336 void URLRequest::ContinueDespiteLastError() { | 343 void URLRequest::ContinueDespiteLastError() { |
| 337 DCHECK(job_); | 344 DCHECK(job_); |
| 338 | 345 |
| 339 job_->ContinueDespiteLastError(); | 346 job_->ContinueDespiteLastError(); |
| 340 } | 347 } |
| 341 | 348 |
| 342 void URLRequest::OrphanJob() { | 349 void URLRequest::OrphanJob() { |
| 350 job_->Kill(); |
| 343 job_->DetachRequest(); // ensures that the job will not call us again | 351 job_->DetachRequest(); // ensures that the job will not call us again |
| 344 job_ = NULL; | 352 job_ = NULL; |
| 345 } | 353 } |
| 346 | 354 |
| 347 // static | 355 // static |
| 348 std::string URLRequest::StripPostSpecificHeaders(const std::string& headers) { | 356 std::string URLRequest::StripPostSpecificHeaders(const std::string& headers) { |
| 349 // These are headers that may be attached to a POST. | 357 // These are headers that may be attached to a POST. |
| 350 static const char* const kPostHeaders[] = { | 358 static const char* const kPostHeaders[] = { |
| 351 "content-type", | 359 "content-type", |
| 352 "content-length", | 360 "content-length", |
| (...skipping 20 matching lines...) Expand all Loading... |
| 373 // following a 302 redirect, normal browsers don't do that. Instead, they | 381 // following a 302 redirect, normal browsers don't do that. Instead, they |
| 374 // all convert a POST into a GET in response to a 302 and so shall we. For | 382 // all convert a POST into a GET in response to a 302 and so shall we. For |
| 375 // 307 redirects, browsers preserve the method. The RFC says to prompt the | 383 // 307 redirects, browsers preserve the method. The RFC says to prompt the |
| 376 // user to confirm the generation of a new POST request, but IE omits this | 384 // user to confirm the generation of a new POST request, but IE omits this |
| 377 // prompt and so shall we. | 385 // prompt and so shall we. |
| 378 strip_post_specific_headers = method_ == "POST"; | 386 strip_post_specific_headers = method_ == "POST"; |
| 379 method_ = "GET"; | 387 method_ = "GET"; |
| 380 } | 388 } |
| 381 url_ = location; | 389 url_ = location; |
| 382 upload_ = NULL; | 390 upload_ = NULL; |
| 383 status_ = URLRequestStatus(); | |
| 384 --redirect_limit_; | 391 --redirect_limit_; |
| 385 | 392 |
| 386 if (strip_post_specific_headers) { | 393 if (strip_post_specific_headers) { |
| 387 // If being switched from POST to GET, must remove headers that were | 394 // If being switched from POST to GET, must remove headers that were |
| 388 // specific to the POST and don't have meaning in GET. For example | 395 // specific to the POST and don't have meaning in GET. For example |
| 389 // the inclusion of a multipart Content-Type header in GET can cause | 396 // the inclusion of a multipart Content-Type header in GET can cause |
| 390 // problems with some servers: | 397 // problems with some servers: |
| 391 // http://code.google.com/p/chromium/issues/detail?id=843 | 398 // http://code.google.com/p/chromium/issues/detail?id=843 |
| 392 // | 399 // |
| 393 // TODO(eroman): It would be better if this data was structured into | 400 // TODO(eroman): It would be better if this data was structured into |
| 394 // specific fields/flags, rather than a stew of extra headers. | 401 // specific fields/flags, rather than a stew of extra headers. |
| 395 extra_request_headers_ = StripPostSpecificHeaders(extra_request_headers_); | 402 extra_request_headers_ = StripPostSpecificHeaders(extra_request_headers_); |
| 396 } | 403 } |
| 397 | 404 |
| 398 if (!final_upload_progress_) { | 405 if (!final_upload_progress_) { |
| 399 final_upload_progress_ = job_->GetUploadProgress(); | 406 final_upload_progress_ = job_->GetUploadProgress(); |
| 400 } | 407 } |
| 401 | 408 |
| 409 job_->Kill(); |
| 402 OrphanJob(); | 410 OrphanJob(); |
| 403 | 411 |
| 412 status_ = URLRequestStatus(); |
| 404 is_pending_ = false; | 413 is_pending_ = false; |
| 405 Start(); | 414 Start(); |
| 406 return net::OK; | 415 return net::OK; |
| 407 } | 416 } |
| 408 | 417 |
| 409 URLRequestContext* URLRequest::context() { | 418 URLRequestContext* URLRequest::context() { |
| 410 return context_.get(); | 419 return context_.get(); |
| 411 } | 420 } |
| 412 | 421 |
| 413 void URLRequest::set_context(URLRequestContext* context) { | 422 void URLRequest::set_context(URLRequestContext* context) { |
| 414 context_ = context; | 423 context_ = context; |
| 415 } | 424 } |
| 416 | 425 |
| 417 int64 URLRequest::GetExpectedContentSize() const { | 426 int64 URLRequest::GetExpectedContentSize() const { |
| 418 int64 expected_content_size = -1; | 427 int64 expected_content_size = -1; |
| 419 if (job_) | 428 if (job_) |
| 420 expected_content_size = job_->expected_content_size(); | 429 expected_content_size = job_->expected_content_size(); |
| 421 | 430 |
| 422 return expected_content_size; | 431 return expected_content_size; |
| 423 } | 432 } |
| 424 | 433 |
| 425 #ifndef NDEBUG | 434 #ifndef NDEBUG |
| 426 | 435 |
| 427 URLRequestMetrics::~URLRequestMetrics() { | 436 URLRequestMetrics::~URLRequestMetrics() { |
| 428 DLOG_IF(WARNING, object_count != 0) << | 437 DLOG_IF(WARNING, object_count != 0) << |
| 429 "Leaking " << object_count << " URLRequest object(s)"; | 438 "Leaking " << object_count << " URLRequest object(s)"; |
| 430 } | 439 } |
| 431 | 440 |
| 432 #endif | 441 #endif |
| OLD | NEW |