private Optional<ErrorResponse> responseFor(DiscFilterRequest request, String ruleName, ErrorResponse response) {
        int statusCode = response != null ? response.getResponse().getStatus() : 0;
        Metric.Context metricContext = metric.createContext(Map.of(
                "rule", ruleName,
                "dryrun", Boolean.toString(dryrun),
                "statusCode", Integer.toString(statusCode)));
        if (response != null) {
            metric.add(ContainerMetrics.JDISC_HTTP_FILTER_RULE_BLOCKED_REQUESTS.baseName(), 1L, metricContext);
            log.log(Level.FINE, () -> String.format(
                    "Blocking request '%h' with status code '%d' using rule '%s' (dryrun=%b)", request, statusCode, ruleName, dryrun));
            return dryrun ? Optional.empty() : Optional.of(response);
        } else {
            metric.add(ContainerMetrics.JDISC_HTTP_FILTER_RULE_ALLOWED_REQUESTS.baseName(), 1L, metricContext);
            log.log(Level.FINE, () -> String.format("Allowing request '%h' using rule '%s' (dryrun=%b)", request, ruleName, dryrun));
            return Optional.empty();
        }
    }
Security request filter that filters requests based on host, method and uri path.

@author bjorncs
jdisc-security-filters/src/main/java/com/yahoo/jdisc/http/filter/security/rule/RuleBasedRequestFilter.java