Configuration options for logging request headers to console

This commit is contained in:
Aurora Lahtela 2023-04-08 07:47:48 +03:00
parent bb6dc692cd
commit 58eae50428
4 changed files with 13 additions and 1 deletions

View File

@ -19,6 +19,7 @@ package com.djrapitops.plan.delivery.webserver.configuration;
import com.djrapitops.plan.delivery.webserver.auth.AllowedIpList; import com.djrapitops.plan.delivery.webserver.auth.AllowedIpList;
import com.djrapitops.plan.delivery.webserver.http.AccessAddressPolicy; import com.djrapitops.plan.delivery.webserver.http.AccessAddressPolicy;
import com.djrapitops.plan.settings.config.PlanConfig; import com.djrapitops.plan.settings.config.PlanConfig;
import com.djrapitops.plan.settings.config.paths.PluginSettings;
import com.djrapitops.plan.settings.config.paths.WebserverSettings; import com.djrapitops.plan.settings.config.paths.WebserverSettings;
import com.djrapitops.plan.storage.file.PlanFiles; import com.djrapitops.plan.storage.file.PlanFiles;
@ -48,6 +49,10 @@ public class WebserverConfiguration {
return webserverLogMessages; return webserverLogMessages;
} }
public boolean isDevMode() {
return config.isTrue(PluginSettings.DEV_MODE);
}
public boolean logAccessToConsole() { public boolean logAccessToConsole() {
return config.isTrue(WebserverSettings.LOG_ACCESS_TO_CONSOLE); return config.isTrue(WebserverSettings.LOG_ACCESS_TO_CONSOLE);
} }

View File

@ -54,6 +54,9 @@ public class AccessLogger {
getRequestURI(internalRequest, request) + getRequestURI(internalRequest, request) +
" (from " + internalRequest.getAccessAddress(webserverConfiguration) + ") - " + " (from " + internalRequest.getAccessAddress(webserverConfiguration) + ") - " +
code; code;
if (webserverConfiguration.isDevMode()) {
message += " Request Headers" + internalRequest.getRequestHeaders();
}
int codeFamily = code - (code % 100); // 5XX, 4XX etc int codeFamily = code - (code % 100); // 5XX, 4XX etc
switch (codeFamily) { switch (codeFamily) {

View File

@ -26,6 +26,7 @@ import com.djrapitops.plan.delivery.webserver.configuration.WebserverConfigurati
import com.djrapitops.plan.utilities.dev.Untrusted; import com.djrapitops.plan.utilities.dev.Untrusted;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
/** /**
@ -54,6 +55,8 @@ public interface InternalRequest {
Request toRequest(); Request toRequest();
Map<String, String> getRequestHeaders();
List<Cookie> getCookies(); List<Cookie> getCookies();
String getMethod(); String getMethod();

View File

@ -81,7 +81,8 @@ public class JettyInternalRequest implements InternalRequest {
return new com.djrapitops.plan.delivery.web.resolver.request.Request(requestMethod, path, query, user, headers, requestBody); return new com.djrapitops.plan.delivery.web.resolver.request.Request(requestMethod, path, query, user, headers, requestBody);
} }
private Map<String, String> getRequestHeaders() { @Override
public Map<String, String> getRequestHeaders() {
return streamHeaderNames() return streamHeaderNames()
.collect(Collectors.toMap(Function.identity(), baseRequest::getHeader, .collect(Collectors.toMap(Function.identity(), baseRequest::getHeader,
(one, two) -> one + ';' + two)); (one, two) -> one + ';' + two));