Skip to content

Commit

Permalink
refactor: redis 의 key 값 수정
Browse files Browse the repository at this point in the history
- userAgent 는 포함하지 않도록
  • Loading branch information
nayonsoso committed Nov 11, 2024
1 parent 18e01f3 commit bb859c8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package reviewme.config.requestlimit;

import static org.springframework.http.HttpHeaders.USER_AGENT;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.util.List;
Expand Down Expand Up @@ -44,13 +42,12 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons

private String generateRequestKey(HttpServletRequest request) {
String requestURI = request.getRequestURI();
String userAgent = request.getHeader(USER_AGENT);
String ip = PROXY_HEADERS.stream()
String remoteAddress = PROXY_HEADERS.stream()
.map(request::getHeader)
.filter(Objects::nonNull)
.findFirst()
.orElse(request.getRemoteAddr());

return String.format("RequestURI: %s, IP: %s, UserAgent: %s", requestURI, ip, userAgent);
return String.format("RequestURI: %s, RemoteAddress: %s", requestURI, remoteAddress);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class RequestLimitInterceptorTest {
private final ValueOperations<String, Long> valueOperations = mock(ValueOperations.class);
private final RequestLimitProperties requestLimitProperties = mock(RequestLimitProperties.class);
private final RequestLimitInterceptor interceptor = new RequestLimitInterceptor(redisTemplate, requestLimitProperties);
private final String requestKey = "RequestURI: /api/v2/reviews, IP: localhost, UserAgent: Postman";
private final String requestKey = "RequestURI: /api/v2/reviews, RemoteAddress: localhost";

@BeforeEach
void setUp() {
Expand Down

0 comments on commit bb859c8

Please sign in to comment.