зеркало из https://github.com/mozilla/gecko-dev.git
bug 718797 - allow heuristic cache of query string resources r=hurley
This commit is contained in:
Родитель
4a0f7cbf1d
Коммит
7b4a70a169
|
@ -3296,14 +3296,11 @@ nsHttpChannel::OnCacheEntryCheck(nsICacheEntry* entry, nsIApplicationCache* appC
|
|||
else if (mCachedResponseHead->MustValidate()) {
|
||||
LOG(("Validating based on MustValidate() returning TRUE\n"));
|
||||
doValidation = true;
|
||||
}
|
||||
else if (MustValidateBasedOnQueryUrl()) {
|
||||
LOG(("Validating based on RFC 2616 section 13.9 "
|
||||
"(query-url w/o explicit expiration-time)\n"));
|
||||
doValidation = true;
|
||||
}
|
||||
// Check if the cache entry has expired...
|
||||
else {
|
||||
} else {
|
||||
// previously we also checked for a query-url w/out expiration
|
||||
// and didn't do heuristic on it. but defacto that is allowed now.
|
||||
//
|
||||
// Check if the cache entry has expired...
|
||||
uint32_t time = 0; // a temporary variable for storing time values...
|
||||
|
||||
rv = entry->GetExpirationTime(&time);
|
||||
|
@ -3799,28 +3796,6 @@ nsHttpChannel::HasQueryString(nsHttpRequestHead::ParsedMethodType method, nsIURI
|
|||
return NS_SUCCEEDED(rv) && !query.IsEmpty();
|
||||
}
|
||||
|
||||
bool
|
||||
nsHttpChannel::MustValidateBasedOnQueryUrl() const
|
||||
{
|
||||
// RFC 2616, section 13.9 states that GET-requests with a query-url
|
||||
// MUST NOT be treated as fresh unless the server explicitly provides
|
||||
// an expiration-time in the response. See bug #468594
|
||||
// Section 13.2.1 (6th paragraph) defines "explicit expiration time"
|
||||
if (mHasQueryString)
|
||||
{
|
||||
uint32_t tmp; // we don't need the value, just whether it's set
|
||||
nsresult rv = mCachedResponseHead->GetExpiresValue(&tmp);
|
||||
if (NS_FAILED(rv)) {
|
||||
rv = mCachedResponseHead->GetMaxAgeValue(&tmp);
|
||||
if (NS_FAILED(rv)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
nsHttpChannel::ShouldUpdateOfflineCacheEntry()
|
||||
{
|
||||
|
|
|
@ -388,7 +388,6 @@ private:
|
|||
|
||||
static bool HasQueryString(nsHttpRequestHead::ParsedMethodType method, nsIURI * uri);
|
||||
bool ResponseWouldVary(nsICacheEntry* entry) const;
|
||||
bool MustValidateBasedOnQueryUrl() const;
|
||||
bool IsResumable(int64_t partialLen, int64_t contentLength,
|
||||
bool ignoreMissingPartialLen = false) const;
|
||||
nsresult MaybeSetupByteRangeRequest(int64_t partialLen, int64_t contentLength,
|
||||
|
|
|
@ -22,15 +22,16 @@ var tests = [
|
|||
{url: "/freshness", server: "0", expected: "0"},
|
||||
{url: "/freshness", server: "1", expected: "0"}, // cached
|
||||
|
||||
// RFC 2616 section 13.9 2nd paragraph
|
||||
// RFC 2616 section 13.9 2nd paragraph says not to heuristically cache
|
||||
// querystring, but we allow it to maintain web compat
|
||||
{url: "/freshness?a", server: "2", expected: "2"},
|
||||
{url: "/freshness?a", server: "3", expected: "3"},
|
||||
{url: "/freshness?a", server: "3", expected: "2"},
|
||||
|
||||
// explicit expiration dates in the future should be cached
|
||||
{url: "/freshness?b", server: "4", expected: "4",
|
||||
responseheader: "Expires: "+getDateString(1)},
|
||||
{url: "/freshness?b", server: "5", expected: "4"},// cached due to Expires
|
||||
|
||||
|
||||
{url: "/freshness?c", server: "6", expected: "6",
|
||||
responseheader: "Cache-Control: max-age=3600"},
|
||||
{url: "/freshness?c", server: "7", expected: "6"}, // cached due to max-age
|
||||
|
@ -39,7 +40,7 @@ var tests = [
|
|||
{url: "/freshness?d", server: "8", expected: "8",
|
||||
responseheader: "Expires: "+getDateString(-1)},
|
||||
{url: "/freshness?d", server: "9", expected: "9"},
|
||||
|
||||
|
||||
{url: "/freshness?e", server: "10", expected: "10",
|
||||
responseheader: "Cache-Control: max-age=0"},
|
||||
{url: "/freshness?e", server: "11", expected: "11"},
|
||||
|
@ -104,7 +105,7 @@ function handler(metadata, response) {
|
|||
var body = metadata.getHeader("x-request");
|
||||
response.setHeader("Content-Type", "text/plain", false);
|
||||
response.setHeader("Date", getDateString(0), false);
|
||||
|
||||
|
||||
var header = tests[index].responseheader;
|
||||
if (header == null) {
|
||||
response.setHeader("Last-Modified", getDateString(-1), false);
|
||||
|
@ -112,11 +113,11 @@ function handler(metadata, response) {
|
|||
var splitHdr = header.split(": ");
|
||||
response.setHeader(splitHdr[0], splitHdr[1], false);
|
||||
}
|
||||
|
||||
|
||||
response.setStatusLine(metadata.httpVersion, 200, "OK");
|
||||
response.bodyOutputStream.write(body, body.length);
|
||||
}
|
||||
|
||||
|
||||
function getDateString(yearDelta) {
|
||||
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
||||
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||
|
|
|
@ -9,7 +9,6 @@ Cu.import("resource://gre/modules/Services.jsm");
|
|||
var httpserver = new HttpServer();
|
||||
var index = 0;
|
||||
var tests = [
|
||||
// RFC 2616 section 13.9 2nd paragraph - query-url should be validated
|
||||
{url: "/freshness?a", server: "0", expected: "0"},
|
||||
{url: "/freshness?a", server: "1", expected: "1"},
|
||||
|
||||
|
@ -20,8 +19,6 @@ var tests = [
|
|||
// Finally, check that request is validated with no flags set
|
||||
{url: "/freshness?a", server: "99", expected: "99"},
|
||||
|
||||
|
||||
// RFC 2616 section 13.9 2nd paragraph - query-url should be validated
|
||||
{url: "/freshness?b", server: "0", expected: "0"},
|
||||
{url: "/freshness?b", server: "1", expected: "1"},
|
||||
|
||||
|
@ -98,6 +95,7 @@ function handler(metadata, response) {
|
|||
var body = metadata.getHeader("x-request");
|
||||
response.setHeader("Content-Type", "text/plain", false);
|
||||
response.setHeader("Date", getDateString(0), false);
|
||||
response.setHeader("Cache-Control", "max-age=0", false);
|
||||
|
||||
var header = tests[index].responseheader;
|
||||
if (header == null) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче