Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added httpCookieStorage and httpHeaders #262

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions netfox/Core/NFX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 8 additions & 1 deletion netfox/Core/NFXProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down