Interface PublicAddress
-
public interface PublicAddressThe advertised public address.This is most commonly used to perform redirects or assemble absolute URLs.
If the default implementation isn't doing what you want it to, you can usually simply configure the public address via
ServerConfigBuilder.publicAddress(java.net.URI). Alternatively, you can register an instance of your own implementation.
-
-
Method Summary
All Methods Static Methods Instance Methods Default Methods Modifier and Type Method Description static PublicAddressbindAddress(RatpackServer server)Uses the serves bind address as the current address.default HttpUrlBuilderbuilder()Creates a URL builder using the public address as the base.default URIget()Returns the public address.default URIget(String path)Creates a URL by appending the given path to the public address.default URIget(Action<? super HttpUrlBuilder> action)Creates a URL by building a URL based on the public address.static PublicAddressinferred(String defaultScheme)An implementation that infers the public address from the current request.static PublicAddressof(URI uri)Creates a new public address object using the given URI.
-
-
-
Method Detail
-
of
static PublicAddress of(URI uri)
Creates a new public address object using the given URI.The path, query and fragment components of the URI will be stripped.
This implementation is implicitly used if a
ServerConfigBuilder.publicAddress(URI)was specified.- Parameters:
uri- the uri- Returns:
- a public address
-
inferred
static PublicAddress inferred(String defaultScheme)
An implementation that infers the public address from the current request.The public address is inferred based on the following:
- X-Forwarded-Host header (if included in request)
- X-Forwarded-Proto or X-Forwarded-Ssl headers (if included in request)
- Absolute request URI (if included in request)
- Host header (if included in request)
- Protocol of request (i.e. http or https)
This implementation is implicitly used if no
ServerConfigBuilder.publicAddress(URI)was specified. WARNING: this implementation is unsafe to use if untrusted clients can influence the request headers mentioned above, as this can lead to cache poisoning attacks. It should only be used when the values for those headers are guaranteed to be trusted, such as when they are guaranteed to be set by a trusted upstream proxy.- Parameters:
defaultScheme- the scheme (httporhttps) if what to use can't be determined from the request- Returns:
- a public address
- Since:
- 1.2
-
bindAddress
static PublicAddress bindAddress(RatpackServer server)
Uses the serves bind address as the current address.This is the default implementation used if no explicit public address was set as part of
ServerConfigBuilder.publicAddress(URI)This implementation throws an
IllegalStateExceptionif the address is queried and the server is not running.- Parameters:
server- the server to use the bind address of- Returns:
- a public address
- Since:
- 1.9
-
get
default URI get()
Returns the public address.The default implementation throws
UnsupportedOperationException, however, all Ratpack provided implemenations properly implement this method.- Returns:
- the public address
- Since:
- 1.2
-
builder
default HttpUrlBuilder builder()
Creates a URL builder using the public address as the base.- Returns:
- a URL builder
- Since:
- 1.2
-
get
default URI get(Action<? super HttpUrlBuilder> action) throws Exception
Creates a URL by building a URL based on the public address.- Parameters:
action- the additions to the public address- Returns:
- the built url
- Throws:
Exception- any thrown byaction- Since:
- 1.2
-
-