@Nullable
    public static CorsPolicy setCorsOrigin(ServiceRequestContext ctx, HttpRequest request,
                                           HttpHeadersBuilder headers, CorsConfig config) {

        final String origin = request.headers().get(HttpHeaderNames.ORIGIN);
        if (origin != null) {
            final CorsPolicy policy = config.getPolicy(origin, ctx.routingContext());
            if (policy == null) {
                logger.debug(
                        "{} There is no CORS policy configured for the request origin '{}' and the path '{}'.",
                        ctx, origin, ctx.path());
                return null;
            }
            if (NULL_ORIGIN.equals(origin)) {
                setCorsNullOrigin(headers);
                return policy;
            }
            if (config.isAnyOriginSupported()) {
                if (policy.isCredentialsAllowed()) {
                    echoCorsRequestOrigin(request, headers);
                    addCorsVaryHeader(headers);
                } else {
                    setCorsAnyOrigin(headers);
                }
                return policy;
            }
            setCorsOrigin(headers, origin);
            addCorsVaryHeader(headers);
            return policy;
        }
        return null;
    }
Sets origin header according to the given CORS configuration and HTTP request.

@param request the HTTP request
@param headers the HTTP headers to modify

@return {@code policy} if CORS configuration matches, otherwise {@code null}
core/src/main/java/com/linecorp/armeria/internal/server/CorsHeaderUtil.java