Class RedirectRefusedException

  • All Implemented Interfaces:
    Serializable

    public final class RedirectRefusedException
    extends Exception
    Thrown when a redirect was refused rather than followed, by AsyncHttpClientConfig.isRefuseSchemeDowngradeOnRedirect() or AsyncHttpClientConfig.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 IOException instead. 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 their IOExceptionFilter replay 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. MaxRedirectException avoids 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 a POST, 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
    • Constructor Detail

      • RedirectRefusedException

        public RedirectRefusedException​(RedirectRefusedException.Reason reason,
                                        int statusCode,
                                        Uri sourceUri,
                                        Uri targetUri)
        Parameters:
        reason - which gate refused the redirect
        statusCode - the status code of the redirect response that was refused
        sourceUri - the URI this hop was leaving
        targetUri - the redirect target that was refused
    • Method Detail

      • 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. Prefer Uri.getBaseUrl() when logging it, as Throwable.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 prefer Uri.getBaseUrl() when logging it, as Throwable.getMessage() already does.
        Returns:
        the refused redirect target, or null on an instance that was deserialized