generated links for files now should respect the "X-Forwarded-Proto" header if the app is behind a well setup reverse proxy

This commit is contained in:
Rostislav Raykov
2024-11-30 22:38:12 +02:00
parent b830e9401d
commit 54431f2bc9

View File

@@ -20,16 +20,12 @@ public class FileUtils {
return String.format("%.2f %s", sizeInUnits, units[unitIndex]);
}
public static long bytesToMegabytes(long bytes) {
return bytes / 1024 / 1024;
}
public static long megabytesToBytes(long megabytes) {
return megabytes * 1024 * 1024;
}
public static String getDownloadLink(HttpServletRequest request, FileEntity fileEntity) {
return request.getScheme() + "://" + request.getServerName() + "/file/" + fileEntity.uuid;
String scheme = request.getHeader("X-Forwarded-Proto");
if (scheme == null) {
scheme = request.getScheme(); // Fallback to the default scheme
}
return scheme + "://" + request.getServerName() + "/file/" + fileEntity.uuid;
}
public static void populateModelAttributes(FileEntity fileEntity, Model model, HttpServletRequest request) {