Class RedirectRefusedException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- org.asynchttpclient.handler.RedirectRefusedException
-
- All Implemented Interfaces:
Serializable
public final class RedirectRefusedException extends Exception
Thrown when a redirect was refused rather than followed, byAsyncHttpClientConfig.isRefuseSchemeDowngradeOnRedirect()orAsyncHttpClientConfig.isRefuseCrossOriginBodyOnRedirect(). The redirected request was never sent.When the origin answers the 3xx before the request content has finished writing, the failed write can surface first and the exchange fails with that
IOExceptioninstead. The content still never reaches the new origin, but a caller branching on this type alone will miss that case.Deliberately not an
IOException: both handlers gate theirIOExceptionFilterreplay on that type, so a refusal that was one would come back as several more attempts to send the content the caller asked to send once.MaxRedirectExceptionavoids it for the same reason.Whether re-sending by hand is safe depends on
getStatusCode(). Every refusal except a 303, and except a 301 or non-strict 302 on aPOST, preserved both the method and the content, so the same request can be aimed somewhere else unchanged. A 303 is intended as an indirect response to a request the origin has very likely already applied (RFC 9110 section 15.4.4), and no status proves otherwise, so a non-idempotent method still needs the caller's judgement (section 9.2.2).- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRedirectRefusedException.ReasonWhich gate refused the redirect.
-
Constructor Summary
Constructors Constructor Description RedirectRefusedException(RedirectRefusedException.Reason reason, int statusCode, Uri sourceUri, Uri targetUri)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RedirectRefusedException.ReasongetReason()@Nullable UrigetSourceUri()The URI this hop was leaving, which is the request actually sent on this leg rather than the one the caller built.intgetStatusCode()@Nullable UrigetTargetUri()The refused target.-
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
-
-
-
Constructor Detail
-
RedirectRefusedException
public RedirectRefusedException(RedirectRefusedException.Reason reason, int statusCode, Uri sourceUri, Uri targetUri)
- Parameters:
reason- which gate refused the redirectstatusCode- the status code of the redirect response that was refusedsourceUri- the URI this hop was leavingtargetUri- the redirect target that was refused
-
-
Method Detail
-
getReason
public RedirectRefusedException.Reason getReason()
- Returns:
- which gate refused the redirect
-
getStatusCode
public int getStatusCode()
- Returns:
- the status code of the redirect response that was refused
-
getSourceUri
@Nullable public @Nullable Uri getSourceUri()
The URI this hop was leaving, which is the request actually sent on this leg rather than the one the caller built. PreferUri.getBaseUrl()when logging it, asThrowable.getMessage()already does.- Returns:
- the URI the refused redirect was leaving, or null on an instance that was deserialized
-
getTargetUri
@Nullable public @Nullable Uri getTargetUri()
The refused target. Its path, query and userinfo are server-chosen, so preferUri.getBaseUrl()when logging it, asThrowable.getMessage()already does.- Returns:
- the refused redirect target, or null on an instance that was deserialized
-
-