mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 09:46:16 +01:00
added request method to mdc filter
This commit is contained in:
@@ -73,6 +73,10 @@ public class MDCFilter extends HttpFilter
|
||||
@VisibleForTesting
|
||||
static final String MDC_REQUEST_URI = "request_uri";
|
||||
|
||||
/** request method */
|
||||
@VisibleForTesting
|
||||
static final String MDC_REQUEST_METHOD = "request_method";
|
||||
|
||||
/** Field description */
|
||||
@VisibleForTesting
|
||||
static final String MDC_USERNAME = "username";
|
||||
@@ -98,6 +102,7 @@ public class MDCFilter extends HttpFilter
|
||||
MDC.put(MDC_USERNAME, getUsername());
|
||||
MDC.put(MDC_CLIEN_IP, request.getRemoteAddr());
|
||||
MDC.put(MDC_CLIEN_HOST, request.getRemoteHost());
|
||||
MDC.put(MDC_REQUEST_METHOD, request.getMethod());
|
||||
MDC.put(MDC_REQUEST_URI, request.getRequestURI());
|
||||
|
||||
try
|
||||
@@ -109,6 +114,7 @@ public class MDCFilter extends HttpFilter
|
||||
MDC.remove(MDC_USERNAME);
|
||||
MDC.remove(MDC_CLIEN_IP);
|
||||
MDC.remove(MDC_CLIEN_HOST);
|
||||
MDC.remove(MDC_REQUEST_METHOD);
|
||||
MDC.remove(MDC_REQUEST_URI);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ public class MDCFilterTest extends AbstractTestBase {
|
||||
when(request.getRequestURI()).thenReturn("api/v1/repositories");
|
||||
when(request.getRemoteAddr()).thenReturn("127.0.0.1");
|
||||
when(request.getRemoteHost()).thenReturn("localhost");
|
||||
when(request.getMethod()).thenReturn("GET");
|
||||
|
||||
MDCCapturingFilterChain chain = new MDCCapturingFilterChain();
|
||||
filter.doFilter(request, response, chain);
|
||||
@@ -96,6 +97,7 @@ public class MDCFilterTest extends AbstractTestBase {
|
||||
assertEquals("api/v1/repositories", chain.ctx.get(MDCFilter.MDC_REQUEST_URI));
|
||||
assertEquals("127.0.0.1", chain.ctx.get(MDCFilter.MDC_CLIEN_IP));
|
||||
assertEquals("localhost", chain.ctx.get(MDCFilter.MDC_CLIEN_HOST));
|
||||
assertEquals("GET", chain.ctx.get(MDCFilter.MDC_REQUEST_METHOD));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user