private void checkCorsValidity()

in src/main/java/com/aliyun/oss/model/SetBucketCORSRequest.java [44:90]


    private void checkCorsValidity(CORSRule corsRule) {
        if (corsRule == null) {
            throw new IllegalArgumentException("corsRule should not be null or empty.");
        }

        if (this.corsRules.size() >= MAX_CORS_RULE_LIMIT) {
            throw new IllegalArgumentException("One bucket not allowed exceed ten items of CORS Rules.");
        }

        // At least one item of allowed origins
        if (corsRule.getAllowedOrigins().isEmpty()) {
            throw new IllegalArgumentException("Required field 'AllowedOrigins' should not be empty.");
        }

        // At least one item of allowed methods
        if (corsRule.getAllowedMethods().isEmpty()) {
            throw new IllegalArgumentException("Required field 'AllowedMethod' should not be empty.");
        }

        // At most one asterisk wildcard in allowed origins
        for (String origin : corsRule.getAllowedOrigins()) {
            if (countOfAsterisk(origin) > 1) {
                throw new IllegalArgumentException("At most one '*' wildcard in allowd origin.");
            }
        }

        // Unsupported method
        for (String method : corsRule.getAllowedMethods()) {
            if (!isAllowedMethod(method)) {
                throw new IllegalArgumentException("Unsupported method " + method + ", (GET,PUT,DELETE,POST,HEAD)");
            }
        }

        // At most one asterisk wildcard in allowed headers
        for (String header : corsRule.getAllowedHeaders()) {
            if (countOfAsterisk(header) > 1) {
                throw new IllegalArgumentException("At most one '*' wildcard in allowd header.");
            }
        }

        // Not allow to use any asterisk wildcard in allowed origins
        for (String header : corsRule.getExposeHeaders()) {
            if (countOfAsterisk(header) > 0) {
                throw new IllegalArgumentException("Not allow to use any '*' wildcard in expose header.");
            }
        }
    }