-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathinvalidation.mjs
121 lines (111 loc) · 2.93 KB
/
invalidation.mjs
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
import { makeTemplate, fresh } from './lib/templates.mjs'
const contentLocation = makeTemplate({
filename: 'content_location_target',
response_headers: [
['Cache-Control', 'max-age=100000'],
['Last-Modified', 0],
['Date', 0]
]
})
const location = makeTemplate({
filename: 'location_target',
response_headers: [
['Cache-Control', 'max-age=100000'],
['Last-Modified', 0],
['Date', 0]
]
})
const lclResponse = makeTemplate({
response_headers: [
['Location', 'location_target'],
['Content-Location', 'content_location_target']
],
magic_locations: true
})
const tests = []
function checkInvalidation (method) {
tests.push({
name: `HTTP cache must invalidate the URL after a successful response to a \`${method}\` request`,
id: `invalidate-${method}`,
depends_on: ['freshness-max-age'],
requests: [
fresh({}), {
request_method: method,
request_body: 'abc',
setup: true
}, {
expected_type: 'not_cached'
}
]
})
tests.push({
name: `An optimal HTTP cache does not invalidate the URL after a failed response to a \`${method}\` request`,
id: `invalidate-${method}-failed`,
kind: 'optimal',
depends_on: [`invalidate-${method}`],
requests: [
fresh({}), {
request_method: method,
request_body: 'abc',
response_status: [500, 'Internal Server Error'],
setup: true
}, {
expected_type: 'cached'
}
]
})
}
function checkLocationInvalidation (method) {
tests.push({
name: `Does HTTP cache invalidate \`Location\` URL after a successful response to a \`${method}\` request?`,
id: `invalidate-${method}-location`,
kind: 'check',
depends_on: [`invalidate-${method}`],
requests: [
location({
setup: true
}), lclResponse({
request_method: method,
request_body: 'abc',
setup: true
}), location({
expected_type: 'not_cached'
})
]
})
}
function checkClInvalidation (method) {
tests.push({
name: `Does HTTP cache must invalidate \`Content-Location\` URL after a successful response to a \`${method}\` request?`,
id: `invalidate-${method}-cl`,
kind: 'check',
depends_on: [`invalidate-${method}`],
requests: [
contentLocation({
setup: true
}), lclResponse({
request_method: method,
request_body: 'abc',
setup: true
}), contentLocation({
expected_type: 'not_cached'
})
]
})
}
const methods = [
'POST',
'PUT',
'DELETE',
'M-SEARCH'
]
methods.forEach(checkInvalidation)
methods.forEach(checkLocationInvalidation)
methods.forEach(checkClInvalidation)
export default {
name: 'Cache Invalidation',
id: 'invalidation',
description: 'These tests check how caches support invalidation, including when it is triggered by the `Location` and `Content-Location` response headers.',
spec_anchors: ['invalidation'],
tests
}