Interface Redirector
-
public interface Redirector
Interprets objects as aLocation
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 adefault 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 thestandard()
implementation.- See Also:
Context.redirect(int, Object)
-
-
Field Summary
Fields Modifier and Type Field Description static com.google.common.reflect.TypeToken<Redirector>
TYPE
A type token for this type.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description void
redirect(Context context, int code, Object to)
Issues a HTTP redirect response, transforming the givento
value into a value for theLocation
header.static Redirector
standard()
The default redirect issuing strategy.
-
-
-
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 givento
value into a value for theLocation
header.Implementations may interpret the
to
value in any manner. Seestandard()
for details on the default strategy.- Parameters:
context
- the request processing context when the redirect was requestedcode
- the status code to issue with the redirectto
- the location to redirect to- Since:
- 1.3
-
-