Get
Get copied to clipboard
Post processing of raw response in delegate, like client(,willSendRequest:)
Could you please add method to APIClientDelegate
for post processing raw response?
Something like this? What use case do you have in mind?
func client(_ client: APIClient, didReceiveResponse response: inout URLResponse, data: Data, task: URLSessionTask) throws
Something like this? What use case do you have in mind?
func client(_ client: APIClient, didReceiveResponse response: inout URLResponse, data: Data, task: URLSessionTask) throws
Yes. Looks what I need.
My use case is setting cookies manually. See the code below.
func postProcess(_ response: HTTPURLResponse) {
if
let url = response.url,
let fields = response.allHeaderFields as? [String: String]
{
let cookies = HTTPCookie.cookies(
withResponseHeaderFields: fields,
for: url
)
let cookieStorage =
client.session.configuration.httpCookieStorage ?? .shared
for cookie in cookies {
cookieStorage.setCookie(cookie)
}
}
}
Got it, thanks. Yes, I was thinking about adding a more comprehensive way of monitoring the session. The existing delegate is designed more for customizing the client behavior. By the way, you can use the existing validateResponse
method as a stop-gap solution.
Got it, thanks. Yes, I was thinking about adding a more comprehensive way of monitoring the session. The existing delegate is designed more for customizing the client behavior. By the way, you can use the existing
validateResponse
method as a stop-gap solution.
Thanks! For the moment I already use validateResponse