MCPcopy Index your code
hub / github.com/scality/cloudserver / findCorsRule

Function findCorsRule

lib/api/apiUtils/object/corsResponse.js:67–80  ·  view source on GitHub ↗

_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)

Source from the content-addressed store, hash-verified

65* @return {(null|object)} - matching rule if found; null if no match
66*/
67function 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

Callers 2

collectCorsHeadersFunction · 0.85
corsPreflightFunction · 0.85

Calls 2

_matchesValueFunction · 0.85
_headersMatchRuleFunction · 0.85

Tested by

no test coverage detected