-
Notifications
You must be signed in to change notification settings - Fork 28
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
Set cookies when playing a track #75
Conversation
I just realized this needs to obey the |
Uses `HTTPCookie.cookies(withResponseHeaderFields:for:)` to generate cookies from the `response`'s `allHeaderFields`. It then sets those cookies using `configuration.httpCookieStorage.setCookies(_:for:mainDocumentURL:)`. The documentation for `setCookies(_:for:mainDocumentURL:)` even says this is the correct way to do this.
Vinyl/Turntable.swift
Outdated
@@ -103,6 +103,12 @@ public final class Turntable: URLSession { | |||
|
|||
return URLSessionTask { | |||
self.operationQueue.addOperation { | |||
// Set cookies | |||
if request.httpShouldHandleCookies, let cookieStorage = self.configuration.httpCookieStorage, let httpResponse = completion.response as? HTTPURLResponse, let headerFields = httpResponse.allHeaderFields as? [String: String], let url = httpResponse.url { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting: could you put each let x =
on a new line? Looks good otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this @brentleyjones, and apologies for the PR being ignored for so long.
Just have one small formatting comment 👍
Uses
HTTPCookie.cookies(withResponseHeaderFields:for:)
to generate cookies from theresponse
'sallHeaderFields
. It then sets those cookies usingconfiguration.httpCookieStorage.setCookies(_:for:mainDocumentURL:)
. The documentation forsetCookies(_:for:mainDocumentURL:)
even says this is the correct way to do this.