OLD | NEW |
1 // Copyright (c) 2006-2009 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/http/http_cache_transaction.h" | 5 #include "net/http/http_cache_transaction.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 | 8 |
9 #if defined(OS_POSIX) | 9 #if defined(OS_POSIX) |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 DCHECK(mode_ & WRITE); | 541 DCHECK(mode_ & WRITE); |
542 | 542 |
543 // Don't set the flag for sparse entries. | 543 // Don't set the flag for sparse entries. |
544 if (partial_.get() && !truncated_) | 544 if (partial_.get() && !truncated_) |
545 return true; | 545 return true; |
546 | 546 |
547 // Double check that there is something worth keeping. | 547 // Double check that there is something worth keeping. |
548 if (!entry_->disk_entry->GetDataSize(kResponseContentIndex)) | 548 if (!entry_->disk_entry->GetDataSize(kResponseContentIndex)) |
549 return false; | 549 return false; |
550 | 550 |
| 551 if (response_.headers->GetContentLength() <= 0 || |
| 552 response_.headers->HasHeaderValue("Accept-Ranges", "none") || |
| 553 !response_.headers->HasStrongValidators()) |
| 554 return false; |
| 555 |
551 truncated_ = true; | 556 truncated_ = true; |
552 target_state_ = STATE_NONE; | 557 target_state_ = STATE_NONE; |
553 next_state_ = STATE_CACHE_WRITE_TRUNCATED_RESPONSE; | 558 next_state_ = STATE_CACHE_WRITE_TRUNCATED_RESPONSE; |
554 DoLoop(OK); | 559 DoLoop(OK); |
555 return true; | 560 return true; |
556 } | 561 } |
557 | 562 |
558 void HttpCache::Transaction::DoCallback(int rv) { | 563 void HttpCache::Transaction::DoCallback(int rv) { |
559 DCHECK(rv != ERR_IO_PENDING); | 564 DCHECK(rv != ERR_IO_PENDING); |
560 DCHECK(callback_); | 565 DCHECK(callback_); |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1135 // We don't want to switch to WRITE mode if we don't have this block of a | 1140 // We don't want to switch to WRITE mode if we don't have this block of a |
1136 // byte-range request because we may have other parts cached. | 1141 // byte-range request because we may have other parts cached. |
1137 custom_request_->extra_headers.append("If-Range: "); | 1142 custom_request_->extra_headers.append("If-Range: "); |
1138 } else { | 1143 } else { |
1139 custom_request_->extra_headers.append("If-None-Match: "); | 1144 custom_request_->extra_headers.append("If-None-Match: "); |
1140 } | 1145 } |
1141 custom_request_->extra_headers.append(etag_value); | 1146 custom_request_->extra_headers.append(etag_value); |
1142 custom_request_->extra_headers.append("\r\n"); | 1147 custom_request_->extra_headers.append("\r\n"); |
1143 // For byte-range requests, make sure that we use only one way to validate | 1148 // For byte-range requests, make sure that we use only one way to validate |
1144 // the request. | 1149 // the request. |
1145 if (partial_.get()) | 1150 if (partial_.get() && !partial_->IsCurrentRangeCached()) |
1146 return true; | 1151 return true; |
1147 } | 1152 } |
1148 | 1153 |
1149 if (!last_modified_value.empty()) { | 1154 if (!last_modified_value.empty()) { |
1150 if (partial_.get() && !partial_->IsCurrentRangeCached()) { | 1155 if (partial_.get() && !partial_->IsCurrentRangeCached()) { |
1151 custom_request_->extra_headers.append("If-Range: "); | 1156 custom_request_->extra_headers.append("If-Range: "); |
1152 } else { | 1157 } else { |
1153 custom_request_->extra_headers.append("If-Modified-Since: "); | 1158 custom_request_->extra_headers.append("If-Modified-Since: "); |
1154 } | 1159 } |
1155 custom_request_->extra_headers.append(last_modified_value); | 1160 custom_request_->extra_headers.append(last_modified_value); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1217 | 1222 |
1218 if (response_code == 304 && partial_->ResponseHeadersOK(headers)) | 1223 if (response_code == 304 && partial_->ResponseHeadersOK(headers)) |
1219 return true; | 1224 return true; |
1220 } else { | 1225 } else { |
1221 // We asked for "If-Range: " so a 206 means just another range. | 1226 // We asked for "If-Range: " so a 206 means just another range. |
1222 if (partial_response && partial_->ResponseHeadersOK(headers)) { | 1227 if (partial_response && partial_->ResponseHeadersOK(headers)) { |
1223 *partial_content = true; | 1228 *partial_content = true; |
1224 return true; | 1229 return true; |
1225 } | 1230 } |
1226 | 1231 |
1227 // 304 is not expected here, but we'll spare the entry. | 1232 // 304 is not expected here, but we'll spare the entry (unless it was |
| 1233 // truncated). |
| 1234 if (truncated_) |
| 1235 failure = true; |
1228 } | 1236 } |
1229 | 1237 |
1230 if (failure) { | 1238 if (failure) { |
1231 // We cannot truncate this entry, it has to be deleted. | 1239 // We cannot truncate this entry, it has to be deleted. |
1232 DoomPartialEntry(false); | 1240 DoomPartialEntry(false); |
1233 mode_ = NONE; | 1241 mode_ = NONE; |
1234 if (!reading_ && !partial_->IsLastRange()) { | 1242 if (!reading_ && !partial_->IsLastRange()) { |
1235 // We'll attempt to issue another network request, this time without us | 1243 // We'll attempt to issue another network request, this time without us |
1236 // messing up the headers. | 1244 // messing up the headers. |
1237 partial_->RestoreHeaders(&custom_request_->extra_headers); | 1245 partial_->RestoreHeaders(&custom_request_->extra_headers); |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1670 response_.cert_request_info = response->cert_request_info; | 1678 response_.cert_request_info = response->cert_request_info; |
1671 } | 1679 } |
1672 return result; | 1680 return result; |
1673 } | 1681 } |
1674 | 1682 |
1675 void HttpCache::Transaction::OnIOComplete(int result) { | 1683 void HttpCache::Transaction::OnIOComplete(int result) { |
1676 DoLoop(result); | 1684 DoLoop(result); |
1677 } | 1685 } |
1678 | 1686 |
1679 } // namespace net | 1687 } // namespace net |
OLD | NEW |