| 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/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/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "net/base/filter.h" | 22 #include "net/base/filter.h" |
| 23 #include "net/base/host_port_pair.h" | 23 #include "net/base/host_port_pair.h" |
| 24 #include "net/base/load_flags.h" | 24 #include "net/base/load_flags.h" |
| 25 #include "net/base/mime_util.h" | 25 #include "net/base/mime_util.h" |
| 26 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
| 27 #include "net/base/net_util.h" | 27 #include "net/base/net_util.h" |
| 28 #include "net/base/network_delegate.h" | 28 #include "net/base/network_delegate.h" |
| 29 #include "net/base/sdch_manager.h" | 29 #include "net/base/sdch_manager.h" |
| 30 #include "net/base/ssl_cert_request_info.h" | 30 #include "net/base/ssl_cert_request_info.h" |
| 31 #include "net/base/ssl_config_service.h" | 31 #include "net/base/ssl_config_service.h" |
| 32 #include "net/http/http_mac_signature.h" | |
| 33 #include "net/http/http_request_headers.h" | 32 #include "net/http/http_request_headers.h" |
| 34 #include "net/http/http_response_headers.h" | 33 #include "net/http/http_response_headers.h" |
| 35 #include "net/http/http_response_info.h" | 34 #include "net/http/http_response_info.h" |
| 36 #include "net/http/http_status_code.h" | 35 #include "net/http/http_status_code.h" |
| 37 #include "net/http/http_transaction.h" | 36 #include "net/http/http_transaction.h" |
| 38 #include "net/http/http_transaction_factory.h" | 37 #include "net/http/http_transaction_factory.h" |
| 39 #include "net/http/http_util.h" | 38 #include "net/http/http_util.h" |
| 40 #include "net/url_request/fraudulent_certificate_reporter.h" | 39 #include "net/url_request/fraudulent_certificate_reporter.h" |
| 41 #include "net/url_request/url_request.h" | 40 #include "net/url_request/url_request.h" |
| 42 #include "net/url_request/url_request_context.h" | 41 #include "net/url_request/url_request_context.h" |
| 43 #include "net/url_request/url_request_error_job.h" | 42 #include "net/url_request/url_request_error_job.h" |
| 44 #include "net/url_request/url_request_redirect_job.h" | 43 #include "net/url_request/url_request_redirect_job.h" |
| 45 #include "net/url_request/url_request_throttler_header_adapter.h" | 44 #include "net/url_request/url_request_throttler_header_adapter.h" |
| 46 #include "net/url_request/url_request_throttler_manager.h" | 45 #include "net/url_request/url_request_throttler_manager.h" |
| 47 | 46 |
| 48 static const char kAvailDictionaryHeader[] = "Avail-Dictionary"; | 47 static const char kAvailDictionaryHeader[] = "Avail-Dictionary"; |
| 49 | 48 |
| 50 namespace net { | 49 namespace net { |
| 51 | 50 |
| 52 namespace { | |
| 53 | |
| 54 void AddAuthorizationHeader( | |
| 55 const std::vector<CookieStore::CookieInfo>& cookie_infos, | |
| 56 HttpRequestInfo* request_info) { | |
| 57 const GURL& url = request_info->url; | |
| 58 const std::string& method = request_info->method; | |
| 59 std::string request_uri = HttpUtil::PathForRequest(url); | |
| 60 const std::string& host = url.host(); | |
| 61 int port = url.EffectiveIntPort(); | |
| 62 for (size_t i = 0; i < cookie_infos.size(); ++i) { | |
| 63 HttpMacSignature signature; | |
| 64 if (!signature.AddStateInfo(cookie_infos[i].name, | |
| 65 cookie_infos[i].creation_date, | |
| 66 cookie_infos[i].mac_key, | |
| 67 cookie_infos[i].mac_algorithm)) { | |
| 68 continue; | |
| 69 } | |
| 70 if (!signature.AddHttpInfo(method, request_uri, host, port)) | |
| 71 continue; | |
| 72 std::string authorization_header; | |
| 73 if (!signature.GenerateAuthorizationHeader(&authorization_header)) | |
| 74 continue; | |
| 75 request_info->extra_headers.SetHeader(HttpRequestHeaders::kAuthorization, | |
| 76 authorization_header); | |
| 77 return; // Only add the first valid header. | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 } // namespace | |
| 82 | |
| 83 class URLRequestHttpJob::HttpFilterContext : public FilterContext { | 51 class URLRequestHttpJob::HttpFilterContext : public FilterContext { |
| 84 public: | 52 public: |
| 85 explicit HttpFilterContext(URLRequestHttpJob* job); | 53 explicit HttpFilterContext(URLRequestHttpJob* job); |
| 86 virtual ~HttpFilterContext(); | 54 virtual ~HttpFilterContext(); |
| 87 | 55 |
| 88 // FilterContext implementation. | 56 // FilterContext implementation. |
| 89 virtual bool GetMimeType(std::string* mime_type) const; | 57 virtual bool GetMimeType(std::string* mime_type) const; |
| 90 virtual bool GetURL(GURL* gurl) const; | 58 virtual bool GetURL(GURL* gurl) const; |
| 91 virtual base::Time GetRequestTime() const; | 59 virtual base::Time GetRequestTime() const; |
| 92 virtual bool IsCachedContent() const; | 60 virtual bool IsCachedContent() const; |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 DoStartTransaction(); | 470 DoStartTransaction(); |
| 503 } | 471 } |
| 504 | 472 |
| 505 void URLRequestHttpJob::OnCookiesLoaded( | 473 void URLRequestHttpJob::OnCookiesLoaded( |
| 506 const std::string& cookie_line, | 474 const std::string& cookie_line, |
| 507 const std::vector<net::CookieStore::CookieInfo>& cookie_infos) { | 475 const std::vector<net::CookieStore::CookieInfo>& cookie_infos) { |
| 508 if (!cookie_line.empty()) { | 476 if (!cookie_line.empty()) { |
| 509 request_info_.extra_headers.SetHeader( | 477 request_info_.extra_headers.SetHeader( |
| 510 HttpRequestHeaders::kCookie, cookie_line); | 478 HttpRequestHeaders::kCookie, cookie_line); |
| 511 } | 479 } |
| 512 if (URLRequest::AreMacCookiesEnabled()) | |
| 513 AddAuthorizationHeader(cookie_infos, &request_info_); | |
| 514 DoStartTransaction(); | 480 DoStartTransaction(); |
| 515 } | 481 } |
| 516 | 482 |
| 517 void URLRequestHttpJob::DoStartTransaction() { | 483 void URLRequestHttpJob::DoStartTransaction() { |
| 518 // We may have been canceled while retrieving cookies. | 484 // We may have been canceled while retrieving cookies. |
| 519 if (GetStatus().is_success()) { | 485 if (GetStatus().is_success()) { |
| 520 StartTransaction(); | 486 StartTransaction(); |
| 521 } else { | 487 } else { |
| 522 NotifyCanceled(); | 488 NotifyCanceled(); |
| 523 } | 489 } |
| (...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1443 return override_response_headers_.get() ? | 1409 return override_response_headers_.get() ? |
| 1444 override_response_headers_ : | 1410 override_response_headers_ : |
| 1445 transaction_->GetResponseInfo()->headers; | 1411 transaction_->GetResponseInfo()->headers; |
| 1446 } | 1412 } |
| 1447 | 1413 |
| 1448 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1414 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
| 1449 awaiting_callback_ = false; | 1415 awaiting_callback_ = false; |
| 1450 } | 1416 } |
| 1451 | 1417 |
| 1452 } // namespace net | 1418 } // namespace net |
| OLD | NEW |