1 |
|
2 | 'use strict'
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | function keysToLowerCase (
|
14 | object /* : MapObject */
|
15 | ) /* : MapObject */ {
|
16 | return Object.keys(object).reduce((result, key) => {
|
17 | result[key.toLowerCase()] = object[key]
|
18 | return result
|
19 | }, {})
|
20 | }
|
21 |
|
22 | function normaliseMethod (
|
23 | method /* : string */
|
24 | ) /* : string */ {
|
25 | return method.toLowerCase()
|
26 | }
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | function protocolFromHeaders (
|
34 | headers /* : Headers */
|
35 | ) /* : Protocol */ {
|
36 | if (headers['x-forwarded-proto'] === 'https') {
|
37 | return `https:`
|
38 | }
|
39 | if (typeof headers.forwarded === 'string' && ~headers.forwarded.indexOf('proto=https')) {
|
40 | return `https:`
|
41 | }
|
42 | if (headers['front-end-https'] === 'on') {
|
43 | return `https:`
|
44 | }
|
45 | return 'http:'
|
46 | }
|
47 |
|
48 | module.exports = {
|
49 | keysToLowerCase,
|
50 | normaliseMethod,
|
51 | protocolFromHeaders
|
52 | }
|