Skip to content

Commit 6a6ba11

Browse files
authored
Exclude OPTIONS requests (#24)
1 parent dd585ca commit 6a6ba11

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/main/java/io/apitally/spring/ApitallyFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public ApitallyFilter(ApitallyClient client) {
4242
@Override
4343
protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response,
4444
@NonNull FilterChain filterChain) throws ServletException, IOException {
45-
if (!client.isEnabled()) {
45+
if (!client.isEnabled() || request.getMethod().equals("OPTIONS")) {
4646
filterChain.doFilter(request, response);
4747
return;
4848
}

src/main/java/io/apitally/spring/ApitallyUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import org.springframework.boot.SpringBootVersion;
88
import org.springframework.core.SpringVersion;
9+
import org.springframework.web.bind.annotation.RequestMethod;
910
import org.springframework.web.servlet.mvc.condition.PathPatternsRequestCondition;
1011
import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition;
1112
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
@@ -19,6 +20,7 @@ public static List<Path> getPaths(RequestMappingHandlerMapping requestMappingHan
1920
.flatMap(entry -> {
2021
RequestMappingInfo mappingInfo = entry.getKey();
2122
return mappingInfo.getMethodsCondition().getMethods().stream()
23+
.filter(method -> method != RequestMethod.OPTIONS && method != RequestMethod.HEAD)
2224
.flatMap(method -> {
2325
PathPatternsRequestCondition pathPatterns = mappingInfo.getPathPatternsCondition();
2426
if (pathPatterns != null && pathPatterns.getPatterns() != null) {

0 commit comments

Comments
 (0)