Interface PublicAddress
-
public interface PublicAddress
The 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 Deprecated Methods Modifier and Type Method Description static PublicAddress
bindAddress(RatpackServer server)
Uses the serves bind address as the current address.default HttpUrlBuilder
builder()
Creates a URL builder using the public address as the base.default HttpUrlBuilder
builder(Context ctx)
Deprecated.since 1.2, usebuilder()
default java.net.URI
get()
Returns the public address.default java.net.URI
get(java.lang.String path)
Creates a URL by appending the given path to the public addressdefault java.net.URI
get(ratpack.func.Action<? super HttpUrlBuilder> action)
Creates a URL by building a URL based on the public address.default java.net.URI
get(Context ctx)
Deprecated.since 1.2default java.net.URI
get(Context ctx, java.lang.String path)
Deprecated.since 1.2, useget(String)
default java.net.URI
get(Context ctx, ratpack.func.Action<? super HttpUrlBuilder> action)
Deprecated.since 1.2, useget(Action)
static PublicAddress
inferred(java.lang.String defaultScheme)
An implementation that infers the public address from the current request.static PublicAddress
of(java.net.URI uri)
Creates a new public address object using the given URI.
-
-
-
Method Detail
-
of
static PublicAddress of(java.net.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(java.lang.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 (http
orhttps
) 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
IllegalStateException
if 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
@Deprecated default java.net.URI get(Context ctx)
Deprecated.since 1.2The advertised public address.This method has been deprecated. Since 1.2, the default implementation simply calls
get()
. Implementations should implement that method only.- Parameters:
ctx
- the handling context at the time the public address is needed- Returns:
- the public address for the context
-
get
default java.net.URI get()
Returns the public address.This method was introduced in 1.2 and supersedes
get(Context)
. The default implementation throwsUnsupportedOperationException
, however, all Ratpack provided implemenations properly implement this method and it should be used instead ofget(Context)
- Returns:
- the public address
- Since:
- 1.2
-
builder
@Deprecated default HttpUrlBuilder builder(Context ctx)
Deprecated.since 1.2, usebuilder()
Creates a URL builder using the public address as the base.- Parameters:
ctx
- the handling context at the time the public address is needed- Returns:
- a URL builder
-
builder
default HttpUrlBuilder builder()
Creates a URL builder using the public address as the base.- Returns:
- a URL builder
- Since:
- 1.2
-
get
@Deprecated default java.net.URI get(Context ctx, ratpack.func.Action<? super HttpUrlBuilder> action) throws java.lang.Exception
Deprecated.since 1.2, useget(Action)
Creates a URL by building a URL based on the public address.- Parameters:
ctx
- the handling context at the time the public address is neededaction
- the additions to the public address- Returns:
- the built url
- Throws:
java.lang.Exception
- any thrown byaction
-
get
default java.net.URI get(ratpack.func.Action<? super HttpUrlBuilder> action) throws java.lang.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:
java.lang.Exception
- any thrown byaction
- Since:
- 1.2
-
get
@Deprecated default java.net.URI get(Context ctx, java.lang.String path)
Deprecated.since 1.2, useget(String)
Creates a URL by appending the given path to the public address- Parameters:
ctx
- the handling context at the time the public address is neededpath
- the path to append to the public address- Returns:
- the public address with the given path appended
-
get
default java.net.URI get(java.lang.String path)
Creates a URL by appending the given path to the public address- Parameters:
path
- the path to append to the public address- Returns:
- the public address with the given path appended
- Since:
- 1.2
-
-