_findCorsRule - Return first matching rule in cors rules that permits * CORS request * @param {object[]} rules - array of rules * @param {string} [rules.id] - optional id to identify rule * @param {string[]} rules[].allowedMethods - methods allowed for CORS * @param {string[]} rules[].allowedOrigi
(rules, origin, method, headers)
| 65 | * @return {(null|object)} - matching rule if found; null if no match |
| 66 | */ |
| 67 | function findCorsRule(rules, origin, method, headers) { |
| 68 | return rules.find(rule => { |
| 69 | if (rule.allowedMethods.indexOf(method) === -1) { |
| 70 | return false; |
| 71 | } else if (!rule.allowedOrigins.some(allowedOrigin => |
| 72 | _matchesValue(allowedOrigin, origin))) { |
| 73 | return false; |
| 74 | } else if (headers && |
| 75 | !_headersMatchRule(headers, rule.allowedHeaders)) { |
| 76 | return false; |
| 77 | } |
| 78 | return true; |
| 79 | }); |
| 80 | } |
| 81 | |
| 82 | /** _gatherResHeaders - Collect headers to return in response |
| 83 | * @param {object} rule - array of rules |
no test coverage detected