RedirectPreventer

public final class RedirectPreventer : NSObject, URLSessionDelegate, URLSessionTaskDelegate

RedirectPreventeris a delegate class that prevents HTTP redirects during URL sessions. This class conforms toURLSessionDelegateandURLSessionTaskDelegateto handle the redirection logic. It ensures that any HTTP redirection responses are not followed by theURLSession`.

  • Called when the session receives a redirection response. This method prevents the redirection by passing nil to the completionHandler.

    Declaration

    Swift

    public func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest, completionHandler: @escaping (URLRequest?) -> Void)

    Parameters

    session

    The session containing the task that received a redirect.

    task

    The task whose request resulted in a redirect.

    response

    The response that caused the redirect.

    request

    A URL request object filled out with the new location.

    completionHandler

    A closure to call with the URL request to allow the redirection, or nil to prevent it.