-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathheaders.mjs
77 lines (70 loc) · 2.22 KB
/
headers.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
import * as templates from './lib/templates.mjs'
import * as utils from './lib/utils.mjs'
import headerList from './lib/header-list.mjs'
const tests = []
tests.push({
name: '`Connection` header must inhibit a HTTP cache from storing listed headers',
id: 'headers-omit-headers-listed-in-Connection',
kind: 'required',
depends_on: ['freshness-max-age'],
requests: [
templates.fresh({
response_headers: [
['Connection', 'a, b', false],
['a', '1', false],
['b', '2', false],
['c', '3', false]
]
}),
{
expected_type: 'cached',
expected_response_headers: [['c', '3']],
expected_response_headers_missing: ['a', 'b'],
setup_tests: ['expected_type', 'expected_response_headers']
}
]
})
function checkStoreHeader (config) {
const id = `store-${config.name}`
const value = 'valB' in config ? config.valB : utils.httpContent(`${config.name}-store-value`)
const storeHeader = 'noStore' in config ? !config.noStore : true
const requirement = storeHeader ? 'must' : 'must not'
const expectedHeaders = storeHeader ? [[config.name, value]] : []
const unexpectedHeaders = storeHeader ? [] : [[config.name, value]]
const respHeaders = [
['Date', 0],
[config.name, value, storeHeader]
]
if (config.name !== 'Cache-Control') {
respHeaders.push(['Cache-Control', 'max-age=3600'])
}
tests.push({
name: `HTTP cache ${requirement} store \`${config.name}\` header field`,
id: `headers-${id}`,
kind: 'required',
depends_on: ['freshness-max-age'],
requests: [
{
response_headers: respHeaders,
setup: true,
pause_after: true,
check_body: 'checkBody' in config ? config.checkBody : true
},
{
expected_type: 'cached',
expected_response_headers: expectedHeaders,
expected_response_headers_missing: unexpectedHeaders,
setup_tests: ['expected_type'],
check_body: 'checkBody' in config ? config.checkBody : true
}
]
})
}
headerList.forEach(checkStoreHeader)
export default {
name: 'Storing Header Fields',
id: 'headers',
description: 'These tests examine how caches store headers in responses.',
spec_anchors: ['storing.fields'],
tests
}