try {
allowedOrigins.add(new Origin(url).validate());
} catch (OriginException e) {
throw new PropertyParseException("Bad origin URL in property cors.allowOrigin: " + url);
}
}
}
// Parse the allow origin suffix matching option
allowSubdomains = pr.getOptBoolean("cors.allowSubdomains", false);
// Parse the supported methods list
String methodSpec = pr.getOptString("cors.supportedMethods", "GET, POST, HEAD, OPTIONS").trim().toUpperCase();
String[] methodNames = parseWords(methodSpec);
supportedMethods = new HashSet<HTTPMethod>();
for (String methodName: methodNames) {
try {
supportedMethods.add(HTTPMethod.valueOf(methodName));
} catch (IllegalArgumentException e) {
throw new PropertyParseException("Bad HTTP method name in property cors.allowMethods: " + methodName);
}
}
// Parse the supported headers list
String headerSpec;
// Empty value has special meaning of "no supported headers"
try {
headerSpec = pr.getString("cors.supportedHeaders");
} catch (PropertyParseException e) {
headerSpec = "*";
}
if (headerSpec.equals("*")) {
supportAnyHeader = true;
supportedHeaders = Collections.unmodifiableSet(new HashSet<HeaderFieldName>());
} else {
supportAnyHeader = false;
String[] headers = parseWords(headerSpec);
supportedHeaders = new HashSet<HeaderFieldName>();
for (String header: headers) {
try {
supportedHeaders.add(new HeaderFieldName(header));
} catch (IllegalArgumentException e) {
throw new PropertyParseException("Bad header field name in property cors.supportedHeaders: " + header);
}
}
}
// Parse the exposed headers list
exposedHeaders = new HashSet<HeaderFieldName>();
for (String header: parseWords(pr.getOptString("cors.exposedHeaders", ""))) {
try {
exposedHeaders.add(new HeaderFieldName(header));
} catch (IllegalArgumentException e) {
throw new PropertyParseException("Bad header field name in property cors.exposedHeaders: " + header);
}
}
// Parse the allow credentials option