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 "content/browser/download/download_manager_impl.h" | 5 #include "content/browser/download/download_manager_impl.h" |
6 | 6 |
7 #include <iterator> | 7 #include <iterator> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 // If we're not at the beginning of the file, retrieve only the remaining | 82 // If we're not at the beginning of the file, retrieve only the remaining |
83 // portion. | 83 // portion. |
84 bool has_last_modified = !params->last_modified().empty(); | 84 bool has_last_modified = !params->last_modified().empty(); |
85 bool has_etag = !params->etag().empty(); | 85 bool has_etag = !params->etag().empty(); |
86 | 86 |
87 // If we've asked for a range, we want to make sure that we only | 87 // If we've asked for a range, we want to make sure that we only |
88 // get that range if our current copy of the information is good. | 88 // get that range if our current copy of the information is good. |
89 // We shouldn't be asked to continue if we don't have a verifier. | 89 // We shouldn't be asked to continue if we don't have a verifier. |
90 DCHECK(params->offset() == 0 || has_etag || has_last_modified); | 90 DCHECK(params->offset() == 0 || has_etag || has_last_modified); |
91 | 91 |
92 if (params->offset() > 0) { | 92 if (params->offset() > 0 && (has_etag || has_last_modified)) { |
93 request->SetExtraRequestHeaderByName( | 93 request->SetExtraRequestHeaderByName( |
94 "Range", | 94 "Range", |
95 base::StringPrintf("bytes=%" PRId64 "-", params->offset()), | 95 base::StringPrintf("bytes=%" PRId64 "-", params->offset()), |
96 true); | 96 true); |
97 | 97 |
98 if (has_last_modified) { | 98 // In accordance with RFC 2616 Section 14.27, use If-Range to specify that |
99 request->SetExtraRequestHeaderByName("If-Unmodified-Since", | 99 // the server return the entire entity if the validator doesn't match. |
100 params->last_modified(), | 100 // Last-Modified can be used in the absence of ETag as a validator if the |
101 true); | 101 // response headers satisfied the HttpUtil::HasStrongValidators() predicate. |
102 } | 102 // |
103 if (has_etag) { | 103 // This function assumes that HasStrongValidators() was true and that the |
104 request->SetExtraRequestHeaderByName("If-Match", params->etag(), true); | 104 // ETag and Last-Modified header values supplied are valid. |
105 } | 105 request->SetExtraRequestHeaderByName( |
| 106 "If-Range", has_etag ? params->etag() : params->last_modified(), true); |
106 } | 107 } |
107 | 108 |
108 for (DownloadUrlParameters::RequestHeadersType::const_iterator iter | 109 for (DownloadUrlParameters::RequestHeadersType::const_iterator iter |
109 = params->request_headers_begin(); | 110 = params->request_headers_begin(); |
110 iter != params->request_headers_end(); | 111 iter != params->request_headers_end(); |
111 ++iter) { | 112 ++iter) { |
112 request->SetExtraRequestHeaderByName( | 113 request->SetExtraRequestHeaderByName( |
113 iter->first, iter->second, false /*overwrite*/); | 114 iter->first, iter->second, false /*overwrite*/); |
114 } | 115 } |
115 | 116 |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 if (delegate_) | 750 if (delegate_) |
750 delegate_->OpenDownload(download); | 751 delegate_->OpenDownload(download); |
751 } | 752 } |
752 | 753 |
753 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { | 754 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { |
754 if (delegate_) | 755 if (delegate_) |
755 delegate_->ShowDownloadInShell(download); | 756 delegate_->ShowDownloadInShell(download); |
756 } | 757 } |
757 | 758 |
758 } // namespace content | 759 } // namespace content |
OLD | NEW |