io.micronaut.web.router.DefaultRequestMatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of micronaut-router Show documentation
Show all versions of micronaut-router Show documentation
Core components supporting the Micronaut Framework
/*
* Copyright 2017-2023 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.web.router;
import io.micronaut.core.annotation.Internal;
import io.micronaut.core.type.Argument;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.MediaType;
import io.micronaut.http.body.MessageBodyHandlerRegistry;
import io.micronaut.inject.MethodExecutionHandle;
import java.util.List;
import java.util.function.Predicate;
/**
* The default {@link RequestMatcher} implementation.
*
* @param The target
* @param The result
* @author Denis Stepanov
* @since 4.0.0
*/
@Internal
public sealed class DefaultRequestMatcher extends DefaultMethodBasedRouteInfo implements RequestMatcher
permits DefaultErrorRouteInfo, DefaultStatusRouteInfo, DefaultUrlRouteInfo {
private final List>> predicates;
public DefaultRequestMatcher(MethodExecutionHandle targetMethod,
Argument> bodyArgument,
String bodyArgumentName,
List producesMediaTypes,
List consumesMediaTypes,
boolean isPermitsBody,
boolean isErrorRoute,
List>> predicates,
MessageBodyHandlerRegistry messageBodyHandlerRegistry) {
super(targetMethod, bodyArgument, bodyArgumentName, producesMediaTypes, consumesMediaTypes, isPermitsBody, isErrorRoute, messageBodyHandlerRegistry);
this.predicates = predicates;
}
@Override
public boolean matching(HttpRequest> httpRequest) {
if (predicates.isEmpty()) {
return true;
}
for (Predicate> predicate : predicates) {
if (!predicate.test(httpRequest)) {
return false;
}
}
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy