         log.error("Error saving the download: \(error)")
       }
     }
+
+    DispatchQueue.main.async {
+      self.handler?.downloadRequestFinished(currentRequest)
+      self.runRequest()
+    }
   }
 
-  func urlSession(_ session: URLSession, dataTask: URLSessionDataTask,
-                  willCacheResponse proposedResponse: CachedURLResponse,
-                  completionHandler: @escaping (CachedURLResponse?) -> Void) {
+  func dataCompletionHandler(data: Data?, response: URLResponse?, error: Error?) -> Void {
+    guard let currentRequest = currentRequest else {
+      return
+    }
+
+    guard let data = data else {
+      DispatchQueue.main.async {
+        self.handler?.downloadRequestFailed(currentRequest)
+        self.runRequest()
+      }
+      return
+    }
     // We only evaluate one at a time, so the 'current request' holds the data task's original request data.
-    currentRequest?.rawResponseData = proposedResponse.data
-    completionHandler(proposedResponse)
+    currentRequest.rawResponseData = data
     // With current internal settings, this will cache the data as we desire.
-  }
 
-  func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
-    let req = currentRequest
-    currentRequest = nil
-    if task.error != nil {
-      //Force the callback onto the main thread.
-      DispatchQueue.main.async {
-        self.handler?.downloadRequestFailed(req!)
-      }
-    } else {
-      DispatchQueue.main.async {
-        self.handler?.downloadRequestFinished(req!)
-      }
-    }
     DispatchQueue.main.async {
+      self.handler?.downloadRequestFinished(currentRequest)
       self.runRequest()
     }
   }

      currentRequest = req

      if req.typeCode == .downloadFile {
        req.task = downloadSession.downloadTask(with: req.url)
        handler?.downloadRequestStarted(req)
      }
      req?.task?.resume()

    self.handler = handler

    let config = URLSessionConfiguration.default
    downloadSession = URLSession(configuration: config)
  }

  func addRequest(_ request: HTTPDownloadRequest) {
