diff --git a/libresonic-main/src/main/java/org/libresonic/player/service/NetworkService.java b/libresonic-main/src/main/java/org/libresonic/player/service/NetworkService.java index 2cc64120..ab522d21 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/service/NetworkService.java +++ b/libresonic-main/src/main/java/org/libresonic/player/service/NetworkService.java @@ -60,8 +60,21 @@ public class NetworkService { private static URI calculateProxyUri(HttpServletRequest request) throws URISyntaxException { String xForardedHost = request.getHeader(X_FORWARDED_HOST); + // If the request has been through multiple reverse proxies, + // We need to return the original Host that the client used + if (xForardedHost != null) { + xForardedHost = xForardedHost.split(",")[0]; + } + if(!isValidXForwardedHost(xForardedHost)) { xForardedHost = request.getHeader(X_FORWARDED_SERVER); + + // If the request has been through multiple reverse proxies, + // We need to return the original Host that the client used + if (xForardedHost != null) { + xForardedHost = xForardedHost.split(",")[0]; + } + if(!isValidXForwardedHost(xForardedHost)) { throw new RuntimeException("Cannot calculate proxy uri without HTTP header " + X_FORWARDED_HOST); }