Hi, it seems not to handle cookies in the (shared) session, yes? no? :) I'd normally make a singleton implementation of the URLSession to handle cookies, for example if cookie auth is used by an api. It requires enabling the usage of HTTPCookieStorage and setting the cookies on every request.
Or is this handled in a super smooth way in your library? :)
Enable cookie storage in the urlsession:
let configuration = URLSessionConfiguration.default
configuration.httpCookieStorage = HTTPCookieStorage.shared
self.session = URLSession(configuration: configuration)
Send cookies with requests
let cookies = HTTPCookieStorage.shared.cookies(for: url) ?? []
let headers = HTTPCookie.requestHeaderFields(with: cookies)
for (headerField, headerValue) in headers {
request.addValue(headerValue, forHTTPHeaderField: headerField)
}
Hi, it seems not to handle cookies in the (shared) session, yes? no? :) I'd normally make a singleton implementation of the URLSession to handle cookies, for example if cookie auth is used by an api. It requires enabling the usage of HTTPCookieStorage and setting the cookies on every request.
Or is this handled in a super smooth way in your library? :)
Enable cookie storage in the urlsession: let configuration = URLSessionConfiguration.default configuration.httpCookieStorage = HTTPCookieStorage.shared self.session = URLSession(configuration: configuration)
Send cookies with requests let cookies = HTTPCookieStorage.shared.cookies(for: url) ?? [] let headers = HTTPCookie.requestHeaderFields(with: cookies) for (headerField, headerValue) in headers { request.addValue(headerValue, forHTTPHeaderField: headerField) }