diff --git a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/CustomRequestLog.java b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/CustomRequestLog.java index f8720bd8961b..f6e9fdc9c118 100644 --- a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/CustomRequestLog.java +++ b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/CustomRequestLog.java @@ -1092,7 +1092,8 @@ private static void logResponseHeader(String arg, StringBuilder b, Request reque @SuppressWarnings("unused") private static void logQueryString(StringBuilder b, Request request, Response response) { - append(b, "?" + request.getHttpURI().getQuery()); + String query = request.getHttpURI().getQuery(); + append(b, (query == null) ? null : "?" + query); } @SuppressWarnings("unused") diff --git a/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/CustomRequestLogTest.java b/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/CustomRequestLogTest.java index 32ce7882fa02..4dc588419188 100644 --- a/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/CustomRequestLogTest.java +++ b/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/CustomRequestLogTest.java @@ -502,6 +502,17 @@ public void testLogQueryString() throws Exception assertThat(log, is("QueryString: ?queryString")); } + @Test + public void testLogEmptyQueryString() throws Exception + { + start("QueryString: %q"); + + HttpTester.Response response = getResponse("GET /path HTTP/1.0\n\n"); + assertEquals(HttpStatus.OK_200, response.getStatus()); + String log = _logs.poll(5, TimeUnit.SECONDS); + assertThat(log, is("QueryString: -")); + } + @Test public void testLogRequestFirstLine() throws Exception {