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
nilto thecompletionHandler.Declaration
Swift
public func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest, completionHandler: @escaping (URLRequest?) -> Void)Parameters
sessionThe session containing the task that received a redirect.
taskThe task whose request resulted in a redirect.
responseThe response that caused the redirect.
requestA URL request object filled out with the new location.
completionHandlerA closure to call with the URL request to allow the redirection, or
nilto prevent it.
View on GitHub