Interface Redirector


  • public interface Redirector
    Interprets objects as a Location header value, and issues the redirect response.

    The redirector is not typically called directly. Instead, handlers use the redirect(Context, int, Object) method (or similar) that obtains a redirector from the context registry. Ratpack provides a default implementation that is used unless a custom implementation is available.

    It is rarely necessary to implement a custom redirector. One reason to do so though is to use domain objects to represent redirect destinations instead of strings. For example, a custom redirector may know how to transform a Person object within your application to a relevant URL. It may be more convenient to implement such a mapping between domain objects and URLs within a custom redirector. Such custom redirectors typically wrap the standard() implementation.

    See Also:
    Context.redirect(int, Object)
    • Field Detail

      • TYPE

        static final com.google.common.reflect.TypeToken<Redirector> TYPE
        A type token for this type.
        Since:
        1.1
    • Method Detail

      • standard

        static Redirector standard()
        The default redirect issuing strategy.

        Ratpack makes this redirector available via the base server registry, making it the default.

        NOTE: prior to version 1.9, redirects were always issued as absolute URLs. Relative redirects were converted to absolute using the PublicAddress. As of 1.9 and later, the relative redirect is issued.

        Returns:
        the standard redirector
        Since:
        1.3
      • redirect

        void redirect​(Context context,
                      int code,
                      Object to)
        Issues a HTTP redirect response, transforming the given to value into a value for the Location header.

        Implementations may interpret the to value in any manner. See standard() for details on the default strategy.

        Parameters:
        context - the request processing context when the redirect was requested
        code - the status code to issue with the redirect
        to - the location to redirect to
        Since:
        1.3