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 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 or https) 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.2
        The 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 throws UnsupportedOperationException, however, all Ratpack provided implemenations properly implement this method and it should be used instead of get(Context)

        Returns:
        the public address
        Since:
        1.2
      • builder

        @Deprecated
        default HttpUrlBuilder builder​(Context ctx)
        Deprecated.
        since 1.2, use builder()
        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, use get(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 needed
        action - the additions to the public address
        Returns:
        the built url
        Throws:
        java.lang.Exception - any thrown by action
      • 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 by action
        Since:
        1.2
      • get

        @Deprecated
        default java.net.URI get​(Context ctx,
                                 java.lang.String path)
        Deprecated.
        since 1.2, use get(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 needed
        path - 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