1 |
|
2 |
|
3 | const toLowerCase = key => {
|
4 | if (typeof key === 'string') {
|
5 | return key.toLowerCase()
|
6 | }
|
7 | return key
|
8 | }
|
9 |
|
10 | module.exports = (initial = {}) => {
|
11 | const headers = new Proxy({}, {
|
12 | get (that, header) {
|
13 | return that[toLowerCase(header)]
|
14 | },
|
15 |
|
16 | set (that, header, value) {
|
17 | that[toLowerCase(header)] = value
|
18 | return true
|
19 | }
|
20 | })
|
21 | Reflect.ownKeys(initial).forEach(header => {
|
22 | headers[header] = initial[header]
|
23 | })
|
24 | return headers
|
25 | }
|