         }
 
         client?.urlProtocolDidFinishLoading(self)
+        session.finishTasksAndInvalidate()
     }
 }
 

                  let url = request.url,
                  url == request.mainDocumentURL else {
                client?.urlProtocol(self, didFailWithError: error)
                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()
    }
