Interface Redirector
-
public interface RedirectorInterprets objects as aLocationheader 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 implementationthat 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
Personobject 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>TYPEA type token for this type.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description voidredirect(Context context, int code, java.lang.Object to)Issues a HTTP redirect response, transforming the giventovalue into a value for theLocationheader.default voidredirect(Context context, java.lang.String to, int code)Deprecated.static Redirectorstandard()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
@Deprecated default void redirect(Context context, java.lang.String to, int code)
Deprecated.Deprecated, replaced byredirect(Context, int, Object).This interface provides a default implementation that simply forwards to
redirect(Context, int, Object).- Parameters:
context- the request processing context when the redirect was requestedto- the location to redirect tocode- the status code to issue with the redirect- See Also:
redirect(Context, int, Object)
-
redirect
void redirect(Context context, int code, java.lang.Object to)
Issues a HTTP redirect response, transforming the giventovalue into a value for theLocationheader.Implementations may interpret the
tovalue 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
-
-