Skip to content

Commit

Permalink
Issue #11490 - fixing CustomRequestLog.setIgnorePaths (#11638)
Browse files Browse the repository at this point in the history
  • Loading branch information
joakime authored Apr 10, 2024
1 parent 66c1c3b commit 83526f7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public void log(Request request, Response response)
{
try
{
if (_ignorePathMap != null && _ignorePathMap.getMatched(request.getHttpURI().toString()) != null)
if (_ignorePathMap != null && _ignorePathMap.getMatched(request.getHttpURI().getCanonicalPath()) != null)
return;

if (_filter != null && !_filter.test(request, response))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;

import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpStatus;
Expand All @@ -49,6 +50,7 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;

import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -71,17 +73,29 @@ public class CustomRequestLogTest

private void start(String formatString) throws Exception
{
start(formatString, new SimpleHandler());
start(formatString, (log) -> {});
}

private void start(String formatString, Consumer<CustomRequestLog> configCustomRequestLog) throws Exception
{
start(formatString, new SimpleHandler(), configCustomRequestLog);
}

private void start(String formatString, Handler handler) throws Exception
{
start(formatString, handler, (log) -> {});
}

private void start(String formatString, Handler handler, Consumer<CustomRequestLog> configCustomRequestLog) throws Exception
{
_server = new Server();
_httpConfig = new HttpConfiguration();
_serverConnector = new ServerConnector(_server, 1, 1, new HttpConnectionFactory(_httpConfig));
_server.addConnector(_serverConnector);
TestRequestLogWriter writer = new TestRequestLogWriter();
_log = new CustomRequestLog(writer, formatString);
if (configCustomRequestLog != null)
configCustomRequestLog.accept(_log);
_server.setRequestLog(_log);
_server.setHandler(handler);
_server.start();
Expand Down Expand Up @@ -141,6 +155,36 @@ public void testRequestFilter() throws Exception
assertNull(log);
}

@ParameterizedTest
@CsvSource(textBlock = """
/foo/a/,true
/zed/b/,false
/zef/c/,true
/zee/d/,false
""")
public void testIgnorePaths(String testPath, boolean existsInLog) throws Exception
{
start("RequestPath: %U",
customRequestLog ->
{
customRequestLog.setIgnorePaths(new String[]{"/zed/*", "/zee/*"});
});

HttpTester.Response response = getResponse("GET @PATH@ HTTP/1.0\n\n".replace("@PATH@", testPath));
assertEquals(HttpStatus.OK_200, response.getStatus());

if (existsInLog)
{
String log = _logs.poll(5, TimeUnit.SECONDS);
assertThat(log, is("RequestPath: " + testPath));
}
else
{
String log = _logs.poll(1, TimeUnit.SECONDS);
assertNull(log);
}
}

@Test
public void testModifier() throws Exception
{
Expand Down

0 comments on commit 83526f7

Please sign in to comment.