Search in sources :

Example 1 with Toggleable

use of io.micronaut.core.util.Toggleable in project micronaut-core by micronaut-projects.

the class DefaultHttpClientFilterResolver method resolveFilters.

@Override
public List<HttpClientFilter> resolveFilters(HttpRequest<?> request, List<FilterEntry<HttpClientFilter>> filterEntries) {
    String requestPath = StringUtils.prependUri("/", request.getUri().getPath());
    io.micronaut.http.HttpMethod method = request.getMethod();
    List<HttpClientFilter> filterList = new ArrayList<>(filterEntries.size());
    for (FilterEntry<HttpClientFilter> filterEntry : filterEntries) {
        final HttpClientFilter filter = filterEntry.getFilter();
        if (filter instanceof Toggleable && !((Toggleable) filter).isEnabled()) {
            continue;
        }
        boolean matches = true;
        if (filterEntry.hasMethods()) {
            matches = anyMethodMatches(method, filterEntry.getFilterMethods());
        }
        if (filterEntry.hasPatterns()) {
            matches = matches && anyPatternMatches(requestPath, filterEntry.getPatterns(), filterEntry.getPatternStyle());
        }
        if (matches) {
            filterList.add(filter);
        }
    }
    return filterList;
}
Also used : HttpMethod(io.micronaut.http.HttpMethod) HttpClientFilter(io.micronaut.http.filter.HttpClientFilter) Toggleable(io.micronaut.core.util.Toggleable) ArrayList(java.util.ArrayList)

Aggregations

Toggleable (io.micronaut.core.util.Toggleable)1 HttpMethod (io.micronaut.http.HttpMethod)1 HttpClientFilter (io.micronaut.http.filter.HttpClientFilter)1 ArrayList (java.util.ArrayList)1