From 117cbc2bd1c386bcb898d3ee1f9cb1bc8cb8032b Mon Sep 17 00:00:00 2001 From: Niels Basjes Date: Wed, 27 Jul 2016 02:31:11 +0200 Subject: [PATCH] Fix NCSA request log in case of missing useragent. (#770) Signed-off-by: Niels Basjes --- .../jetty/server/AbstractNCSARequestLog.java | 2 +- .../jetty/server/handler/RequestLogTest.java | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractNCSARequestLog.java b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractNCSARequestLog.java index a65d9b36ff5..8aa9bf36313 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractNCSARequestLog.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractNCSARequestLog.java @@ -242,7 +242,7 @@ public abstract class AbstractNCSARequestLog extends AbstractLifeCycle implement String agent = request.getHeader(HttpHeader.USER_AGENT.toString()); if (agent == null) - b.append("\"-\" "); + b.append("\"-\""); else { b.append('"'); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/RequestLogTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/RequestLogTest.java index b5a43530c29..4e575e863e5 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/RequestLogTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/RequestLogTest.java @@ -188,11 +188,31 @@ public class RequestLogTest assertThat(log,containsString("GET /foo ")); assertThat(log,containsString(" 400 0 ")); } - + + @Test + public void testUseragentWithout() throws Exception + { + _connector.getResponses("GET http://[:1]/foo HTTP/1.1\nReferer: http://other.site\n\n"); + String log = _log.exchange(null,5,TimeUnit.SECONDS); + assertThat(log,containsString("GET http://[:1]/foo ")); + assertThat(log,containsString(" 400 0 \"http://other.site\" \"-\" - ")); + } + + @Test + public void testUseragentWith() throws Exception + { + _connector.getResponses("GET http://[:1]/foo HTTP/1.1\nReferer: http://other.site\nUser-Agent: Mozilla/5.0 (test)\n\n"); + String log = _log.exchange(null,5,TimeUnit.SECONDS); + assertThat(log,containsString("GET http://[:1]/foo ")); + assertThat(log,containsString(" 400 0 \"http://other.site\" \"Mozilla/5.0 (test)\" - ")); + } + private class Log extends AbstractNCSARequestLog { { super.setExtended(true); + super.setLogLatency(true); + super.setLogCookies(true); } @Override