Using Alamofire, is it possible to have a function to handle the response of the header before downloading the full file?
For instance:
Our application uses the same elements on several pages. These items are collected using the query. Each request has its own hash (md5 checksum). We send this hash in the headers, and I want to abort the request if the hash is recognized in the cache system.
Implementation example
APIManager.sharedManager.request(url, method: method, parameters: parameters)
.doSomethingHere {
}
.responseJSON { response in
}
}
Edit: solution (implementation of Alamofire SWIFT 3)
APIManager.sharedManager.delegate.dataTaskDidReceiveResponse =
{(session:URLSession, dataTask:URLSessionDataTask, response:URLResponse) -> URLSession.ResponseDisposition in
if let httpResponse = response as? HTTPURLResponse {
return URLSession.ResponseDisposition.cancel
}
return URLSession.ResponseDisposition.allow
}
APIManager.sharedManager.request(url, method: method, parameters: parameters)
.responseJSON { response in
}
}
source
share