Class HttpRequestServerUrlBuilder
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 Summary
Modifier and TypeMethodDescriptionstatic StringgetServerRootUrl(jakarta.servlet.http.HttpServletRequest request) Builds the public server root URL, honoringX-Forwarded-*headers unconditionally (backward-compatible behavior).static StringgetServerRootUrl(jakarta.servlet.http.HttpServletRequest request, TrustedProxies trustedProxies) Builds the public server root URL (scheme + host + optional port).static StringserverRootFromBaseUrl(String baseUrl) Extracts the server root (scheme://host[:port]) from an explicitly configured base URL such asaos.baseUrlOverwrite, discarding any path, query, fragment and userinfo.
-
Method Details
-
getServerRootUrl
Builds the public server root URL, honoringX-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 requesttrustedProxies- an optional allowlist; whennullor empty, forwarded headers are honored unconditionally, otherwise they are honored only when the request's remote address is a trusted proxy
-
serverRootFromBaseUrl
Extracts the server root (scheme://host[:port]) from an explicitly configured base URL such asaos.baseUrlOverwrite, discarding any path, query, fragment and userinfo. Returnsnullwhen the value is blank, not an absolute hierarchical URL, or otherwise unparseable, so callers can fall back to detection.
-