OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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_http_job.h" | 5 #include "net/url_request/url_request_http_job.h" |
6 | 6 |
7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/file_version_info.h" | 11 #include "base/file_version_info.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "net/base/cert_status_flags.h" | 15 #include "net/base/cert_status_flags.h" |
16 #include "net/base/cookie_monster.h" | 16 #include "net/base/cookie_monster.h" |
17 #include "net/base/filter.h" | 17 #include "net/base/filter.h" |
18 #include "net/base/force_tls_state.h" | 18 #include "net/base/force_tls_state.h" |
19 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
20 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
21 #include "net/base/net_util.h" | 21 #include "net/base/net_util.h" |
22 #include "net/base/sdch_manager.h" | 22 #include "net/base/sdch_manager.h" |
| 23 #include "net/base/ssl_cert_request_info.h" |
23 #include "net/http/http_response_headers.h" | 24 #include "net/http/http_response_headers.h" |
24 #include "net/http/http_response_info.h" | 25 #include "net/http/http_response_info.h" |
25 #include "net/http/http_transaction.h" | 26 #include "net/http/http_transaction.h" |
26 #include "net/http/http_transaction_factory.h" | 27 #include "net/http/http_transaction_factory.h" |
27 #include "net/http/http_util.h" | 28 #include "net/http/http_util.h" |
28 #include "net/url_request/url_request.h" | 29 #include "net/url_request/url_request.h" |
29 #include "net/url_request/url_request_context.h" | 30 #include "net/url_request/url_request_context.h" |
30 #include "net/url_request/url_request_error_job.h" | 31 #include "net/url_request/url_request_error_job.h" |
31 | 32 |
32 // TODO(darin): make sure the port blocking code is not lost | 33 // TODO(darin): make sure the port blocking code is not lost |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 // Because we set the AUTH_STATE_CANCELED flag, NeedsAuth will return false, | 378 // Because we set the AUTH_STATE_CANCELED flag, NeedsAuth will return false, |
378 // which will cause the consumer to receive OnResponseStarted instead of | 379 // which will cause the consumer to receive OnResponseStarted instead of |
379 // OnAuthRequired. | 380 // OnAuthRequired. |
380 // | 381 // |
381 // We have to do this via InvokeLater to avoid "recursing" the consumer. | 382 // We have to do this via InvokeLater to avoid "recursing" the consumer. |
382 // | 383 // |
383 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 384 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
384 this, &URLRequestHttpJob::OnStartCompleted, net::OK)); | 385 this, &URLRequestHttpJob::OnStartCompleted, net::OK)); |
385 } | 386 } |
386 | 387 |
| 388 void URLRequestHttpJob::ContinueWithCertificate( |
| 389 net::X509Certificate* client_cert) { |
| 390 DCHECK(transaction_.get()); |
| 391 |
| 392 DCHECK(!response_info_) << "should not have a response yet"; |
| 393 |
| 394 // No matter what, we want to report our status as IO pending since we will |
| 395 // be notifying our consumer asynchronously via OnStartCompleted. |
| 396 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 397 |
| 398 int rv = transaction_->RestartWithCertificate(client_cert, &start_callback_); |
| 399 if (rv == net::ERR_IO_PENDING) |
| 400 return; |
| 401 |
| 402 // The transaction started synchronously, but we need to notify the |
| 403 // URLRequest delegate via the message loop. |
| 404 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
| 405 this, &URLRequestHttpJob::OnStartCompleted, rv)); |
| 406 } |
| 407 |
387 void URLRequestHttpJob::ContinueDespiteLastError() { | 408 void URLRequestHttpJob::ContinueDespiteLastError() { |
388 // If the transaction was destroyed, then the job was cancelled. | 409 // If the transaction was destroyed, then the job was cancelled. |
389 if (!transaction_.get()) | 410 if (!transaction_.get()) |
390 return; | 411 return; |
391 | 412 |
392 DCHECK(!response_info_) << "should not have a response yet"; | 413 DCHECK(!response_info_) << "should not have a response yet"; |
393 | 414 |
394 // No matter what, we want to report our status as IO pending since we will | 415 // No matter what, we want to report our status as IO pending since we will |
395 // be notifying our consumer asynchronously via OnStartCompleted. | 416 // be notifying our consumer asynchronously via OnStartCompleted. |
396 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 417 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 | 467 |
447 if (result == net::OK) { | 468 if (result == net::OK) { |
448 NotifyHeadersComplete(); | 469 NotifyHeadersComplete(); |
449 } else if (ShouldTreatAsCertificateError(result)) { | 470 } else if (ShouldTreatAsCertificateError(result)) { |
450 // We encountered an SSL certificate error. Ask our delegate to decide | 471 // We encountered an SSL certificate error. Ask our delegate to decide |
451 // what we should do. | 472 // what we should do. |
452 // TODO(wtc): also pass ssl_info.cert_status, or just pass the whole | 473 // TODO(wtc): also pass ssl_info.cert_status, or just pass the whole |
453 // ssl_info. | 474 // ssl_info. |
454 request_->delegate()->OnSSLCertificateError( | 475 request_->delegate()->OnSSLCertificateError( |
455 request_, result, transaction_->GetResponseInfo()->ssl_info.cert); | 476 request_, result, transaction_->GetResponseInfo()->ssl_info.cert); |
| 477 } else if (result == net::ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { |
| 478 request_->delegate()->OnCertificateRequested( |
| 479 request_, transaction_->GetResponseInfo()->cert_request_info); |
456 } else { | 480 } else { |
457 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); | 481 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); |
458 } | 482 } |
459 } | 483 } |
460 | 484 |
461 void URLRequestHttpJob::OnReadCompleted(int result) { | 485 void URLRequestHttpJob::OnReadCompleted(int result) { |
462 read_in_progress_ = false; | 486 read_in_progress_ = false; |
463 | 487 |
464 if (result == 0) { | 488 if (result == 0) { |
465 NotifyDone(URLRequestStatus()); | 489 NotifyDone(URLRequestStatus()); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 if (!ctx || !ctx->force_tls_state()) | 723 if (!ctx || !ctx->force_tls_state()) |
700 return; | 724 return; |
701 | 725 |
702 std::string name = "X-Force-TLS"; | 726 std::string name = "X-Force-TLS"; |
703 std::string value; | 727 std::string value; |
704 | 728 |
705 void* iter = NULL; | 729 void* iter = NULL; |
706 while (response_info_->headers->EnumerateHeader(&iter, name, &value)) | 730 while (response_info_->headers->EnumerateHeader(&iter, name, &value)) |
707 ctx->force_tls_state()->DidReceiveHeader(request_info_.url, value); | 731 ctx->force_tls_state()->DidReceiveHeader(request_info_.url, value); |
708 } | 732 } |
OLD | NEW |