public abstract class Redirector
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static Redirector |
DEFAULT
Default instance.
|
static Redirector |
NO_REDIRECT
No redirections are performed.
|
Constructor and Description |
---|
Redirector() |
Modifier and Type | Method and Description |
---|---|
static Redirector |
createStandardInstance(int[] redirectCodes)
Returns an instance that redirects on a given list of 3xx codes.
|
java.net.URL |
getRedirectUrl(java.net.URLConnection conn)
Returns a URL to which connections should be redirected from
a supplied URL connection, according to this redirector's policy.
|
abstract boolean |
isRedirect(int responseCode)
Indicates whether a given HTTP response code should be followed
as a redirect.
|
abstract boolean |
willRedirect(java.lang.String fromProto,
java.lang.String toProto)
Indicates whether HTTP 3xx redirection is permitted between
two URL protocols.
|
public static final Redirector DEFAULT
public static final Redirector NO_REDIRECT
public abstract boolean isRedirect(int responseCode)
responseCode
- HTTP response codepublic abstract boolean willRedirect(java.lang.String fromProto, java.lang.String toProto)
The behaviour of the J2SE
HttpURLConnection.setInstanceFollowRedirects(boolean)
method
is that redirection is only permitted beween identical protocols
(for instance HTTP->HTTP, but not HTTP->HTTPS),
see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4620571.
This is for security reasons, but considerations of the same
arguments could reasonably lead to weaker restrictions.
fromProto
- protocol part of source URLtoProto
- protocol part of destination URLURL.getProtocol()
public java.net.URL getRedirectUrl(java.net.URLConnection conn) throws java.io.IOException
conn
- URL connection; will be connected if it is not alreadyjava.io.IOException
- if there is a problem with the redirection
(for instance missing Location header)public static Redirector createStandardInstance(int[] redirectCodes)
redirectCodes
- list of zero or more 3xx codes which are
to be treated as redirects