 //---------------------------------------------------------------------------
 
 private class WebCacheFetcherBridge : NSObject, NSURLSessionDataDelegate {
-    unowned var fetcher: WebCacheFetcher
-
-    init(fetcher: WebCacheFetcher) {
-        self.fetcher = fetcher
+    var trustSelfSignedServer: Bool
+
+    init(trustSelfSignedServer: Bool) {
+        self.trustSelfSignedServer = trustSelfSignedServer
     }
 
     func abortTask(task: NSURLSessionTask, error: NSError?) {

    private var session: NSURLSession!
    private var bridge: WebCacheFetcherBridge!

    public init(configuration: NSURLSessionConfiguration? = nil) {
        self.bridge = WebCacheFetcherBridge(fetcher: self)
        self.session = NSURLSession(configuration: configuration ?? NSURLSessionConfiguration.ephemeralSessionConfiguration(), delegate: self.bridge, delegateQueue: nil)
    }


    @objc func URLSession(session: NSURLSession, dataTask: NSURLSessionDataTask, willCacheResponse proposedResponse: NSCachedURLResponse, completionHandler: (NSCachedURLResponse?) -> Void) {
        completionHandler(nil)
    }

    @objc func URLSession(session: NSURLSession, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential?) -> Void) {
        if self.trustSelfSignedServer && challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
            let credential = NSURLCredential(forTrust: challenge.protectionSpace.serverTrust!)
            completionHandler(.UseCredential, credential)
        } else {
            completionHandler(.PerformDefaultHandling, nil)
        }
    }
}

