1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
// META: global=window,worker
// META: title=HTTP Cache - Cache-Control Request Directives
// META: timeout=long
// META: script=/common/utils.js
// META: script=/common/get-host-info.sub.js
// META: script=http-cache.js
var tests = [
{
name: "HTTP cache doesn't use aged but fresh response when request contains Cache-Control: max-age=0",
requests: [
{
template: "fresh",
pause_after: true
},
{
request_headers: [
["Cache-Control", "max-age=0"]
],
expected_type: "not_cached"
}
]
},
{
name: "HTTP cache doesn't use aged but fresh response when request contains Cache-Control: max-age=1",
requests: [
{
template: "fresh",
pause_after: true
},
{
request_headers: [
["Cache-Control", "max-age=1"]
],
expected_type: "not_cached"
}
]
},
{
name: "HTTP cache doesn't use fresh response with Age header when request contains Cache-Control: max-age that is greater than remaining freshness",
requests: [
{
response_headers: [
["Cache-Control", "max-age=3600"],
["Age", "1800"]
]
},
{
request_headers: [
["Cache-Control", "max-age=600"]
],
expected_type: "not_cached"
}
]
},
{
name: "HTTP cache does use aged stale response when request contains Cache-Control: max-stale that permits its use",
requests: [
{
response_headers: [
["Cache-Control", "max-age=1"]
],
pause_after: true
},
{
request_headers: [
["Cache-Control", "max-stale=1000"]
],
expected_type: "cached"
}
]
},
{
name: "HTTP cache does reuse stale response with Age header when request contains Cache-Control: max-stale that permits its use",
requests: [
{
response_headers: [
["Cache-Control", "max-age=1500"],
["Age", "2000"]
]
},
{
request_headers: [
["Cache-Control", "max-stale=1000"]
],
expected_type: "cached"
}
]
},
{
name: "HTTP cache doesn't reuse fresh response when request contains Cache-Control: min-fresh that wants it fresher",
requests: [
{
response_headers: [
["Cache-Control", "max-age=1500"]
]
},
{
request_headers: [
["Cache-Control", "min-fresh=2000"]
],
expected_type: "not_cached"
}
]
},
{
name: "HTTP cache doesn't reuse fresh response with Age header when request contains Cache-Control: min-fresh that wants it fresher",
requests: [
{
response_headers: [
["Cache-Control", "max-age=1500"],
["Age", "1000"]
]
},
{
request_headers: [
["Cache-Control", "min-fresh=1000"]
],
expected_type: "not_cached"
}
]
},
{
name: "HTTP cache doesn't reuse fresh response when request contains Cache-Control: no-cache",
requests: [
{
response_headers: [
["Cache-Control", "max-age=3600"]
]
},
{
request_headers: [
["Cache-Control", "no-cache"]
],
expected_type: "not_cached"
}
]
},
{
name: "HTTP cache validates fresh response with Last-Modified when request contains Cache-Control: no-cache",
requests: [
{
response_headers: [
["Cache-Control", "max-age=3600"],
["Last-Modified", -10000]
]
},
{
request_headers: [
["Cache-Control", "no-cache"]
],
expected_type: "lm_validate"
}
]
},
{
name: "HTTP cache validates fresh response with ETag when request contains Cache-Control: no-cache",
requests: [
{
response_headers: [
["Cache-Control", "max-age=3600"],
["ETag", http_content("abc")]
]
},
{
request_headers: [
["Cache-Control", "no-cache"]
],
expected_type: "etag_validate"
}
]
},
{
name: "HTTP cache doesn't reuse fresh response when request contains Cache-Control: no-store",
requests: [
{
response_headers: [
["Cache-Control", "max-age=3600"]
]
},
{
request_headers: [
["Cache-Control", "no-store"]
],
expected_type: "not_cached"
}
]
},
{
name: "HTTP cache generates 504 status code when nothing is in cache and request contains Cache-Control: only-if-cached",
requests: [
{
request_headers: [
["Cache-Control", "only-if-cached"]
],
expected_status: 504,
expected_response_text: null
}
]
}
];
run_tests(tests);
|