forked from sveltejs/kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
headers.js
72 lines (57 loc) · 1.85 KB
/
headers.js
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
import '../src/shims.js';
import { suite } from 'uvu';
import * as assert from 'uvu/assert';
import { split_headers } from '../src/headers.js';
const test = suite('Netlify Adapter Header Utilities');
test('empty headers', () => {
const headers = new Headers();
const result = split_headers(headers);
assert.equal(result, {
headers: {},
multiValueHeaders: {},
});
})
test('single-value headers', () => {
const headers = new Headers();
headers.append('Location', '/apple');
headers.append('Content-Type', 'application/json');
const result = split_headers(headers);
assert.equal(result, {
headers: {
// Note: becomes lowercase even if specified as uppercase
'location': '/apple',
'content-type': 'application/json',
},
multiValueHeaders: {},
});
})
test('multi-value headers', () => {
const headers = new Headers();
headers.append('Set-Cookie', 'flavor=sugar');
headers.append('Set-Cookie', 'diameter=6cm');
const result = split_headers(headers);
assert.equal(result, {
headers: {},
multiValueHeaders: {
'set-cookie': ['flavor=sugar', 'diameter=6cm'],
},
});
})
test('multi-value cookies with expiry', () => {
const wednesday = new Date(1645650108262).toUTCString()
const thursday = new Date(1645736508262).toUTCString()
const headers = new Headers();
headers.append('Set-Cookie', `flavor=sugar; Expires=${wednesday}`);
headers.append('Set-Cookie', `diameter=6cm; Expires=${thursday}`);
const result = split_headers(headers);
assert.equal(result, {
headers: {},
multiValueHeaders: {
'set-cookie': [
`flavor=sugar; Expires=${wednesday}`,
`diameter=6cm; Expires=${thursday}`,
],
},
});
})
test.run()