Class HttpRequestServerUrlBuilder

java.lang.Object
org.alfresco.module.aosmodule.util.HttpRequestServerUrlBuilder

public final class HttpRequestServerUrlBuilder extends Object
Builds public-facing server root URLs from an HTTP request.

This is a single, shared implementation (module alfresco-aos-commons) used by both the standalone _vti_bin web application and the repository binding.

Header trust: by default the X-Forwarded-* headers are honored (backward compatible). Callers may pass a non-empty TrustedProxies allowlist to restrict header trust to requests whose immediate peer (ServletRequest.getRemoteAddr()) is a configured proxy. When the peer is not trusted the forwarded headers are ignored and the URL is derived conservatively from the request.

The legacy X-Forwarded-Proto/-Host/-Port headers and the RFC 7239 Forwarded header are both supported. When both are present the legacy X-Forwarded-* values take precedence (for backward compatibility) and the RFC 7239 Forwarded header fills in any component the legacy headers do not provide. Only the first Forwarded forwarded-element (the one closest to the client) is considered, and only its proto and host parameters are used. For a deterministic, proxy-agnostic result, set aos.baseUrlOverwrite.

  • Method Details

    • getServerRootUrl

      public static String getServerRootUrl(jakarta.servlet.http.HttpServletRequest request)
      Builds the public server root URL, honoring X-Forwarded-* headers unconditionally (backward-compatible behavior).
    • getServerRootUrl

      public static String getServerRootUrl(jakarta.servlet.http.HttpServletRequest request, TrustedProxies trustedProxies)
      Builds the public server root URL (scheme + host + optional port). Does not include context path or site path.
      Parameters:
      request - the incoming request
      trustedProxies - an optional allowlist; when null or empty, forwarded headers are honored unconditionally, otherwise they are honored only when the request's remote address is a trusted proxy
    • serverRootFromBaseUrl

      public static String serverRootFromBaseUrl(String baseUrl)
      Extracts the server root (scheme://host[:port]) from an explicitly configured base URL such as aos.baseUrlOverwrite, discarding any path, query, fragment and userinfo. Returns null when the value is blank, not an absolute hierarchical URL, or otherwise unparseable, so callers can fall back to detection.