I'm trying to configure Alamofire to follow redirects (or not) on a per-request basis.
Alamofire has a private internal class SessionDelegate
which serves as the NSURLSessionTaskDelegate
for the current URL session. SessionDelegate
does implement the relevant delegate method, URLSession(session:, task:, willPerformHTTPRedirection response:, request:, completionHandler:)
which is exactly what I want.
Even better, the delegate's implementation consults a custom variable closure named taskWillPerformHTTPRedirection
to determine how to handle the redirect - again, exactly what I want!
And as far as I can tell, that closure is always nil
by default -- it is not assigned to internally by Alamofire -- which suggests that it is intended to let the user assign a closure to it.
The problem: I cannot access this private SessionDelegate
class to assign a closure to its taskWillPerformHTTPRedirection
variable. It is a private class and it is not visible to my Swift files. What is the proper means of configuring an Alamofire request to (not) follow redirects?