Fix NCSA request log in case of missing useragent. (#770)

Signed-off-by: Niels Basjes <niels@basjes.nl>
This commit is contained in:
Niels Basjes 2016-07-27 02:31:11 +02:00 committed by Greg Wilkins
parent 1d0c43548a
commit 117cbc2bd1
2 changed files with 22 additions and 2 deletions

View File

@ -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('"');

View File

@ -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