RequestParser { void logSiteHeaders(HeaderMap headers, ActionLog actionLog) { if (logSiteHeaders) { String userAgent = headers.getFirst(Headers.USER_AGENT); if (userAgent != null) actionLog.context("user_agent", userAgent); String referer = headers.getFirst(Headers.REFERER); if (referer != null) actionLog.context("referer", Strings.truncate(referer, 1000)); } }  void parse(RequestImpl request, HttpServerExchange exchange, ActionLog actionLog); final ClientIPParser clientIPParser; public boolean logSiteHeaders; }
@Test void logSiteHeaders() { var headers = new HeaderMap(); headers.put(Headers.REFERER, "http: headers.put(Headers.USER_AGENT, "Mozilla/5.0"); var actionLog = new ActionLog(null, null); parser.logSiteHeaders(headers, actionLog); assertThat(actionLog.context).doesNotContainKeys("user_agent", "referer"); parser.logSiteHeaders = true; parser.logSiteHeaders(headers, actionLog); assertThat(actionLog.context).containsKeys("user_agent", "referer"); }