SAPHTTPCookieStorage
public class SAPHTTPCookieStorage : HTTPCookieStorage
The SAP implemented HTTPCookieStorage which can be used with instances of SAPURLSession.
The store can be initialized with a CodableStoring instance which makes it capable to persist cookies between application runs.
This implementation won’t share the non-session cookies among the other SAPHTTPCookieStorage instances per default.
Example:
let sessionConfiguration = URLSessionConfiguration.default
sessionConfiguration.httpCookieStorage = sapCookieStorage
let sapUrlSession = SAPURLSession(configuration: sessionConfiguration)
-
The underlying persistent storage, in which the non-session cookies are stored.
Declaration
Swift
public private(set) var persistentStorage: CodableStoring? { get } -
Options to influence the behavior of
SAPHTTPCookieStorageOptionsDeclaration
Swift
public var options: SAPHTTPCookieStorageOptions { get set } -
Instantiates the cookie store.
Declaration
Swift
public init(persistentStorage: CodableStoring? = nil, options: SAPHTTPCookieStorageOptions = .default)Parameters
persistentStoragethe
CodableStoringused to persist to cookiesoptionsto influence the behavior of
SAPHTTPCookieStorageOptions
-
The cookie accept policy preference of the receiver.
Declaration
Swift
override public var cookieAcceptPolicy: HTTPCookie.AcceptPolicy { get set } -
An array of the currently available
HTTPCookies.Declaration
Swift
override public var cookies: [HTTPCookie]? { get }
-
Returns an array of cookies to send to the given URL. The cookie manager examines the cookies it stores and includes those which should be sent to the given URL. You can use +[NSCookie requestHeaderFieldsWithCookies:] to turn this array into a set of header fields to add to a request.
Declaration
Swift
override public func cookies(for URL: URL) -> [HTTPCookie]?Parameters
URLThe URL for which to get cookies.
Return Value
an array of
HTTPCookie -
Note: This method currently does not sort! Returns an array of all cookies in the store, sorted according to the key value and sorting direction of the NSSortDescriptors specified in the parameter. Proper sorting of cookies may require extensive string conversion, which can be avoided by allowing the system to perform the sorting. This API is to be preferred over the more generic -[NSHTTPCookieStorage cookies] API, if sorting is going to be performed.
Declaration
Swift
override public func sortedCookies(using sortOrder: [NSSortDescriptor]) -> [HTTPCookie]Parameters
sortOrderan array of NSSortDescriptors which represent the preferred sort order of the resulting array.
-
Sets a cookie, following the cookie accept policy. The cookie will override an existing cookie with the same name, domain and path, if any.
Declaration
Swift
override public func setCookie(_ cookie: HTTPCookie)Parameters
cookiethe cookie to set
-
Adds an array cookies to the cookie store, following the cookie accept policy. For mainDocumentURL, the caller should pass the URL for an appropriate main document, if known. For example, when loading a web page, the URL of the main html document for the top-level frame should be passed. To save cookies based on a set of response headers, you can use +[NSCookie cookiesWithResponseHeaderFields:forURL:] on a header field dictionary and then use this method to store the resulting cookies in accordance with policy settings.
Declaration
Swift
override public func setCookies(_ cookies: [HTTPCookie], for URL: URL?, mainDocumentURL: URL?)Parameters
cookiesthe cookies to set
URLthe URL from which the cookies were sent
mainDocumentURLthe main document URL to be used as a base for the “same domain as main document” policy
-
Delete the specified cookie.
Declaration
Swift
override public func deleteCookie(_ cookie: HTTPCookie)Parameters
cookiethe cookie to delete
-
Delete all cookies from the cookie storage since the provided date.
Declaration
Swift
override public func removeCookies(since date: Date)Parameters
datethe date from which the cookies should be deleted
-
Set a new
persistentStoragewhile retaining cookies from previouspersistentStorageDeclaration
Swift
public func setPersistentStorage(_ newPersistentStorage: CodableStoring)Parameters
newPersistentStoragekeeps existing cookies (if any) and will store cookies from previous
persistentStorageinstance
-
Sets an array of cookies for the given URLSessionTask.
Declaration
Swift
override public func storeCookies(_ cookies: [HTTPCookie], for task: URLSessionTask)Parameters
cookiesthe cookies to set
taskthe task to relate the cookies to
-
Retrieves an array of cookies corresponding to the given URLSessionTask.
Declaration
Swift
override public func getCookiesFor(_ task: URLSessionTask, completionHandler: @escaping ([HTTPCookie]?) -> Swift.Void)Parameters
taskthe task for which the cookies needed
completionHandlerthe completionHandler that gets called with the array of cookies