Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions java/src/main/java/com/genexus/webpanels/HttpContextWeb.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class HttpContextWeb extends HttpContext {
private static final String SAME_SITE_LAX = "Lax";
private static final String SAME_SITE_STRICT = "Strict";
private static final String SET_COOKIE = "Set-Cookie";
private static String httpForwardedHeadersEnabled = System.getenv("HTTP_FORWARDEDHEADERS_ENABLED");

public static final int BROWSER_OTHER = 0;
public static final int BROWSER_IE = 1;
Expand Down Expand Up @@ -630,8 +631,10 @@ public String getUserId(String key, ModelContext context, int handle, com.genexu
}

public String getRemoteAddr() {
boolean isEnabled = "true".equalsIgnoreCase(httpForwardedHeadersEnabled);
String address = getHeader("X-Forwarded-For");
if (address.length() > 0){
if (isEnabled && address != null && address.length() > 0) {
address = address.split(",")[0].trim();
return address;
}
address = request.getRemoteAddr();
Expand Down Expand Up @@ -948,18 +951,16 @@ public byte setCookie(String name, String value, String path, java.util.Date exp
}

public String getServerName() {
boolean isEnabled = "true".equalsIgnoreCase(httpForwardedHeadersEnabled);
String host = getHeader("X-Forwarded-Host");
if (host.length() > 0){
return host;
if (isEnabled && host != null && host.length() > 0) {
return host.split(",")[0].trim();
}
String serverNameProperty = ModelContext.getModelContext().getPreferences().getProperty("SERVER_NAME", "");
if (!StringUtils.isBlank(serverNameProperty)) {
return serverNameProperty;
}
if (request != null)
return request.getServerName();

return "";
return request != null ? request.getServerName() : "";
}

public int getServerPort() {
Expand Down
Loading