public interface PublicAddress
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.
Modifier and Type | Method and Description |
---|---|
default HttpUrlBuilder |
builder()
Creates a URL builder using the public address as the base.
|
default HttpUrlBuilder |
builder(Context ctx)
Deprecated.
since 1.2, use
builder() |
default java.net.URI |
get()
Returns the public address.
|
default java.net.URI |
get(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.2
|
default java.net.URI |
get(Context ctx,
Action<? super HttpUrlBuilder> action)
Deprecated.
since 1.2, use
get(Action) |
default java.net.URI |
get(Context ctx,
java.lang.String path)
Deprecated.
since 1.2, use
get(String) |
default java.net.URI |
get(java.lang.String path)
Creates a URL by appending the given path to the public address
|
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.
|
static PublicAddress of(java.net.URI 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.
uri
- the uristatic PublicAddress inferred(java.lang.String defaultScheme)
The public address is inferred based on the following:
This implementation is implicitly used if no ServerConfigBuilder.publicAddress(URI)
was specified.
defaultScheme
- the scheme (http
or https
) if what to use can't be determined from the request@Deprecated default java.net.URI get(Context ctx)
This method has been deprecated.
Since 1.2, the default implementation simply calls get()
.
Implementations should implement that method only.
ctx
- the handling context at the time the public address is neededdefault java.net.URI get()
This method was introduced in 1.2 and supersedes get(Context)
.
The default implementation throws UnsupportedOperationException
, however, all Ratpack provided implemenations
properly implement this method and it should be used instead of get(Context)
@Deprecated default HttpUrlBuilder builder(Context ctx)
builder()
ctx
- the handling context at the time the public address is neededdefault HttpUrlBuilder builder()
@Deprecated default java.net.URI get(Context ctx, Action<? super HttpUrlBuilder> action) throws java.lang.Exception
get(Action)
ctx
- the handling context at the time the public address is neededaction
- the additions to the public addressjava.lang.Exception
- any thrown by action
default java.net.URI get(Action<? super HttpUrlBuilder> action) throws java.lang.Exception
action
- the additions to the public addressjava.lang.Exception
- any thrown by action
@Deprecated default java.net.URI get(Context ctx, java.lang.String path)
get(String)
ctx
- the handling context at the time the public address is neededpath
- the path to append to the public addressdefault java.net.URI get(java.lang.String path)
path
- the path to append to the public address