Skip to content

Commit

Permalink
Use getServletPath instead of getPathInfo for jakarta servlets
Browse files Browse the repository at this point in the history
  • Loading branch information
kul committed May 8, 2024
1 parent 5c86608 commit 80bc276
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public ServletLimiterBuilder partitionByParameter(String name) {
* @return Chainable builder
*/
public ServletLimiterBuilder partitionByPathInfo(Function<String, String> pathToGroup) {
return partitionResolver(request -> Optional.ofNullable(request.getPathInfo()).map(pathToGroup).orElse(null));
return partitionResolver(request -> Optional.ofNullable(request.getServletPath()).map(pathToGroup).orElse(null));
}

/**
Expand Down Expand Up @@ -129,7 +129,7 @@ public ServletLimiterBuilder bypassLimitByParameter(String name, String value) {
* @return Chainable builder
*/
public ServletLimiterBuilder bypassLimitByPathInfo(String pathInfo) {
return bypassLimitResolver((context) -> pathInfo.equals(context.getPathInfo()));
return bypassLimitResolver((context) -> pathInfo.equals(context.getServletPath()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void testDoFilterBypassCheckPassedForPath() throws ServletException, IOEx

MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setPathInfo("/admin/health");
request.setServletPath("/admin/health");
MockHttpServletResponse response = new MockHttpServletResponse();
MockFilterChain filterChain = new MockFilterChain();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private HttpServletRequest createMockRequestWithPrincipal(String name) {
private HttpServletRequest createMockRequestWithPathInfo(String name) {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);

Mockito.when(request.getPathInfo()).thenReturn(name);
Mockito.when(request.getServletPath()).thenReturn(name);
return request;
}
}

0 comments on commit 80bc276

Please sign in to comment.