diff --git a/netfox/Core/NFX.swift b/netfox/Core/NFX.swift index eaf2eab9..0e0a51e8 100755 --- a/netfox/Core/NFX.swift +++ b/netfox/Core/NFX.swift @@ -69,6 +69,9 @@ open class NFX: NSObject { case shake case custom } + // There are some cases while using Alamofire we needd to store cookies in the default http storage + @objc public static var globalCookieStorage: HTTPCookieStorage? + @objc public static var defaultHTTPHeaders: [AnyHashable: Any]? @objc open func start() { guard !started else { diff --git a/netfox/Core/NFXProtocol.swift b/netfox/Core/NFXProtocol.swift index db49585d..d6f45fc3 100755 --- a/netfox/Core/NFXProtocol.swift +++ b/netfox/Core/NFXProtocol.swift @@ -12,7 +12,14 @@ open class NFXProtocol: URLProtocol { static let nfxInternalKey = "com.netfox.NFXInternal" private lazy var session: URLSession = { [unowned self] in - return URLSession(configuration: .default, delegate: self, delegateQueue: nil) + let config = URLSessionConfiguration.default + if let globalCookieStorage = NFX.globalCookieStorage { + config.httpCookieStorage = NFX.globalCookieStorage + } + if let defaultHTTPHeaders = NFX.defaultHTTPHeaders { + config.httpAdditionalHeaders = defaultHTTPHeaders + } + return URLSession(configuration: config, delegate: self, delegateQueue: nil) }() private let model = NFXHTTPModel()