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

Set cookies when playing a track #75

Merged
merged 6 commits into from
Aug 16, 2018
Merged

Set cookies when playing a track #75

merged 6 commits into from
Aug 16, 2018

Conversation

brentleyjones
Copy link
Contributor

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.

@brentleyjones
Copy link
Contributor Author

I just realized this needs to obey the request.httpShouldHandleCookies property.

brentleyjones and others added 2 commits June 15, 2017 08:41
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.
@@ -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 {
Copy link
Contributor

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.

Copy link
Contributor

@mluisbrown mluisbrown left a 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 👍

@dmcrodrigues dmcrodrigues merged commit d91e488 into Velhotes:master Aug 16, 2018
@brentleyjones brentleyjones deleted the bj/cookies branch August 16, 2018 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants