                   let url = request.url,
                   url == request.mainDocumentURL else {
                 client?.urlProtocol(self, didFailWithError: error)
+                session.finishTasksAndInvalidate()
                 return
             }
 

           originalRequest.url != currentRequest.url {
                let response = URLResponse()
                client?.urlProtocol(self, wasRedirectedTo: currentRequest, redirectResponse: response)
                return
        }


        mutableRequest.addValue("1", forHTTPHeaderField: "DNT")

        let configuration = URLSessionConfiguration.default
        let session = URLSession(configuration: configuration, delegate: self, delegateQueue: nil)
        dataTask = session.dataTask(with: mutableRequest)
        dataTask?.resume()
    }
