diff --git a/Digger.podspec b/Digger.podspec index 8709e00..df29693 100755 --- a/Digger.podspec +++ b/Digger.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "Digger" - s.version = "0.0.5" + s.version = "0.0.6" s.summary = "A lightweight download framework that requires only one line of code to complete the file download task" s.homepage = "https://github.com/cornerAnt/Digger" s.license = { :type => "MIT", :file => "LICENSE" } diff --git a/Sources/DiggerManager.swift b/Sources/DiggerManager.swift index ffa6470..6dcf76b 100644 --- a/Sources/DiggerManager.swift +++ b/Sources/DiggerManager.swift @@ -64,14 +64,21 @@ open class DiggerManager:DiggerManagerProtocol { let count = maxConcurrentTasksCount == 0 ? 1 : maxConcurrentTasksCount session.invalidateAndCancel() - session = setupSession(allowsCellularAccess, count) + session = setupSession(allowsCellularAccess, count, additionalHTTPHeaders) } } public var allowsCellularAccess: Bool = true { didSet{ session.invalidateAndCancel() - session = setupSession(allowsCellularAccess, maxConcurrentTasksCount) + session = setupSession(allowsCellularAccess, maxConcurrentTasksCount, additionalHTTPHeaders) + } + } + + public var additionalHTTPHeaders: [String: String] = [:] { + didSet { + session.invalidateAndCancel() + session = setupSession(allowsCellularAccess, maxConcurrentTasksCount, additionalHTTPHeaders) } } @@ -90,6 +97,7 @@ open class DiggerManager:DiggerManagerProtocol { let sessionConfiguration = URLSessionConfiguration.default sessionConfiguration.allowsCellularAccess = allowsCellularAccess sessionConfiguration.httpMaximumConnectionsPerHost = maxConcurrentTasksCount + sessionConfiguration.httpAdditionalHeaders = additionalHTTPHeaders session = URLSession(configuration: sessionConfiguration, delegate: diggerDelegate, delegateQueue: delegateQueue) } @@ -100,11 +108,12 @@ open class DiggerManager:DiggerManagerProtocol { - private func setupSession(_ allowsCellularAccess:Bool ,_ maxDownloadTasksCount:Int ) -> URLSession{ + private func setupSession(_ allowsCellularAccess:Bool ,_ maxDownloadTasksCount:Int, _ additionalHTTPHeaders:[String:String] ) -> URLSession{ diggerDelegate = DiggerDelegate() let sessionConfiguration = URLSessionConfiguration.default sessionConfiguration.allowsCellularAccess = allowsCellularAccess sessionConfiguration.httpMaximumConnectionsPerHost = maxDownloadTasksCount + sessionConfiguration.httpAdditionalHeaders = additionalHTTPHeaders let session = URLSession(configuration: sessionConfiguration, delegate: diggerDelegate, delegateQueue: delegateQueue) return session