| 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.h" | 5 #include "net/http/http_cache.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 struct HeaderNameAndValue { | 74 struct HeaderNameAndValue { |
| 75 const char* name; | 75 const char* name; |
| 76 const char* value; | 76 const char* value; |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 // If the request includes one of these request headers, then avoid caching | 79 // If the request includes one of these request headers, then avoid caching |
| 80 // to avoid getting confused. | 80 // to avoid getting confused. |
| 81 static const HeaderNameAndValue kPassThroughHeaders[] = { | 81 static const HeaderNameAndValue kPassThroughHeaders[] = { |
| 82 { "if-unmodified-since", NULL }, // causes unexpected 412s | 82 { "if-unmodified-since", NULL }, // causes unexpected 412s |
| 83 { "if-match", NULL }, // causes unexpected 412s | 83 { "if-match", NULL }, // causes unexpected 412s |
| 84 { "if-range", NULL }, |
| 84 { NULL, NULL } | 85 { NULL, NULL } |
| 85 }; | 86 }; |
| 86 | 87 |
| 87 struct ValidationHeaderInfo { | 88 struct ValidationHeaderInfo { |
| 88 const char* request_header_name; | 89 const char* request_header_name; |
| 89 const char* related_response_header_name; | 90 const char* related_response_header_name; |
| 90 }; | 91 }; |
| 91 | 92 |
| 92 static const ValidationHeaderInfo kValidationHeaders[] = { | 93 static const ValidationHeaderInfo kValidationHeaders[] = { |
| 93 { "if-modified-since", "last-modified" }, | 94 { "if-modified-since", "last-modified" }, |
| (...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 if (LowerCaseEqualsASCII(it.name_begin(), it.name_end(), | 798 if (LowerCaseEqualsASCII(it.name_begin(), it.name_end(), |
| 798 info.request_header_name)) { | 799 info.request_header_name)) { |
| 799 num_validation_headers++; | 800 num_validation_headers++; |
| 800 validation_header.type_index = i; | 801 validation_header.type_index = i; |
| 801 validation_header.value = it.values(); | 802 validation_header.value = it.values(); |
| 802 break; | 803 break; |
| 803 } | 804 } |
| 804 } | 805 } |
| 805 } | 806 } |
| 806 | 807 |
| 808 // We don't support ranges and validation headers. |
| 809 if (range_found && num_validation_headers) { |
| 810 LOG(WARNING) << "Byte ranges AND validation headers found."; |
| 811 effective_load_flags_ |= LOAD_DISABLE_CACHE; |
| 812 } |
| 813 |
| 807 if (range_found && !(effective_load_flags_ & LOAD_DISABLE_CACHE)) { | 814 if (range_found && !(effective_load_flags_ & LOAD_DISABLE_CACHE)) { |
| 808 partial_.reset(new PartialData); | 815 partial_.reset(new PartialData); |
| 809 if (partial_->Init(request_->extra_headers, new_extra_headers)) { | 816 if (partial_->Init(request_->extra_headers, new_extra_headers)) { |
| 810 // We will be modifying the actual range requested to the server, so | 817 // We will be modifying the actual range requested to the server, so |
| 811 // let's remove the header here. | 818 // let's remove the header here. |
| 812 custom_request_.reset(new HttpRequestInfo(*request_)); | 819 custom_request_.reset(new HttpRequestInfo(*request_)); |
| 813 request_ = custom_request_.get(); | 820 request_ = custom_request_.get(); |
| 814 custom_request_->extra_headers = new_extra_headers; | 821 custom_request_->extra_headers = new_extra_headers; |
| 815 } else { | 822 } else { |
| 816 // The range is invalid or we cannot handle it properly. | 823 // The range is invalid or we cannot handle it properly. |
| 824 LOG(WARNING) << "Invalid byte range found."; |
| 817 effective_load_flags_ |= LOAD_DISABLE_CACHE; | 825 effective_load_flags_ |= LOAD_DISABLE_CACHE; |
| 818 partial_.reset(NULL); | 826 partial_.reset(NULL); |
| 819 } | 827 } |
| 820 } | 828 } |
| 821 | 829 |
| 822 // If there is more than one validation header, we can't treat this request as | 830 // If there is more than one validation header, we can't treat this request as |
| 823 // a cache validation, since we don't know for sure which header the server | 831 // a cache validation, since we don't know for sure which header the server |
| 824 // will give us a response for (and they could be contradictory). | 832 // will give us a response for (and they could be contradictory). |
| 825 if (num_validation_headers > 1) { | 833 if (num_validation_headers > 1) { |
| 826 LOG(WARNING) << "Multiple validation headers found."; | 834 LOG(WARNING) << "Multiple validation headers found."; |
| (...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2110 static_cast<net::HttpNetworkLayer*>(network_layer_.get()); | 2118 static_cast<net::HttpNetworkLayer*>(network_layer_.get()); |
| 2111 HttpNetworkSession* session = network->GetSession(); | 2119 HttpNetworkSession* session = network->GetSession(); |
| 2112 if (session) { | 2120 if (session) { |
| 2113 session->tcp_socket_pool()->CloseIdleSockets(); | 2121 session->tcp_socket_pool()->CloseIdleSockets(); |
| 2114 } | 2122 } |
| 2115 } | 2123 } |
| 2116 | 2124 |
| 2117 //----------------------------------------------------------------------------- | 2125 //----------------------------------------------------------------------------- |
| 2118 | 2126 |
| 2119 } // namespace net | 2127 } // namespace net |
| OLD | NEW |