Using HTTPSCookiesStorage can I screen(filter) cookies storage in URLSession?












2















I have subclassed HTTPCookiesStorage, but the storeCookies() never store the cookies although, i am calling super.storeCookies() within the method.



Session stores the cookies automatically if i dont override the configuration with my custom httpCookiesSession object. I am kind of lost here.



This is the URLSession call



   var configration = URLSessionConfiguration.default
//configration.httpCookieStorage = customHTTPCookiesStorage()

let session = URLSession.init(configuration: configration)



if let url = URL.init(string: "https://google.com"){
session.dataTask(with: url) { sip,sap,su in
print(sip,sap,su)

var x = session.configuration.httpCookieStorage?.cookies

}.resume()
}


This is the custom class



class customHTTPCookiesStorage: HTTPCookieStorage {

override func storeCookies(_ cookies: [HTTPCookie], for task: URLSessionTask) {

super.storeCookies(cookies, for: task)
for cookies in cookies{
session?.session.configuration.httpCookieStorage?.setCookie(cookies)
}

print("This is where cookies are stored")
}
}


Update 1
My aim is not to store the cookies in httpcookiesstore when Http response status in 401










share|improve this question

























  • And what happens when you set a breakpoint on the line that calls super.storeCookies(...)?

    – Caleb
    Nov 23 '18 at 5:09











  • so cookies are available, in the cookies variable. if I put a breakpoint. but never gets stored automatically. i am sure the for loop i have written in not required but even after successful iterations of for loop, httpcookiesstorage is empty, i was wondering if i am overriding the correct methods and if there is another elegant way of doing so. i just dont want to store cookies in when the status code in 401.

    – Hunble Dhillon
    Nov 23 '18 at 5:19













  • developer.apple.com/documentation/foundation/httpcookiestorage have a look at the subclassing section.

    – Hunble Dhillon
    Nov 23 '18 at 5:25













  • Why is configration.httpCookieStorage = customHTTPCookiesStorage() commented out?

    – Caleb
    Nov 23 '18 at 6:28











  • I commented that out to check if the cookies were being stored otherwise. and they were. I can upload the project in some public repo if you want to check that out?

    – Hunble Dhillon
    Nov 23 '18 at 6:49
















2















I have subclassed HTTPCookiesStorage, but the storeCookies() never store the cookies although, i am calling super.storeCookies() within the method.



Session stores the cookies automatically if i dont override the configuration with my custom httpCookiesSession object. I am kind of lost here.



This is the URLSession call



   var configration = URLSessionConfiguration.default
//configration.httpCookieStorage = customHTTPCookiesStorage()

let session = URLSession.init(configuration: configration)



if let url = URL.init(string: "https://google.com"){
session.dataTask(with: url) { sip,sap,su in
print(sip,sap,su)

var x = session.configuration.httpCookieStorage?.cookies

}.resume()
}


This is the custom class



class customHTTPCookiesStorage: HTTPCookieStorage {

override func storeCookies(_ cookies: [HTTPCookie], for task: URLSessionTask) {

super.storeCookies(cookies, for: task)
for cookies in cookies{
session?.session.configuration.httpCookieStorage?.setCookie(cookies)
}

print("This is where cookies are stored")
}
}


Update 1
My aim is not to store the cookies in httpcookiesstore when Http response status in 401










share|improve this question

























  • And what happens when you set a breakpoint on the line that calls super.storeCookies(...)?

    – Caleb
    Nov 23 '18 at 5:09











  • so cookies are available, in the cookies variable. if I put a breakpoint. but never gets stored automatically. i am sure the for loop i have written in not required but even after successful iterations of for loop, httpcookiesstorage is empty, i was wondering if i am overriding the correct methods and if there is another elegant way of doing so. i just dont want to store cookies in when the status code in 401.

    – Hunble Dhillon
    Nov 23 '18 at 5:19













  • developer.apple.com/documentation/foundation/httpcookiestorage have a look at the subclassing section.

    – Hunble Dhillon
    Nov 23 '18 at 5:25













  • Why is configration.httpCookieStorage = customHTTPCookiesStorage() commented out?

    – Caleb
    Nov 23 '18 at 6:28











  • I commented that out to check if the cookies were being stored otherwise. and they were. I can upload the project in some public repo if you want to check that out?

    – Hunble Dhillon
    Nov 23 '18 at 6:49














2












2








2








I have subclassed HTTPCookiesStorage, but the storeCookies() never store the cookies although, i am calling super.storeCookies() within the method.



Session stores the cookies automatically if i dont override the configuration with my custom httpCookiesSession object. I am kind of lost here.



This is the URLSession call



   var configration = URLSessionConfiguration.default
//configration.httpCookieStorage = customHTTPCookiesStorage()

let session = URLSession.init(configuration: configration)



if let url = URL.init(string: "https://google.com"){
session.dataTask(with: url) { sip,sap,su in
print(sip,sap,su)

var x = session.configuration.httpCookieStorage?.cookies

}.resume()
}


This is the custom class



class customHTTPCookiesStorage: HTTPCookieStorage {

override func storeCookies(_ cookies: [HTTPCookie], for task: URLSessionTask) {

super.storeCookies(cookies, for: task)
for cookies in cookies{
session?.session.configuration.httpCookieStorage?.setCookie(cookies)
}

print("This is where cookies are stored")
}
}


Update 1
My aim is not to store the cookies in httpcookiesstore when Http response status in 401










share|improve this question
















I have subclassed HTTPCookiesStorage, but the storeCookies() never store the cookies although, i am calling super.storeCookies() within the method.



Session stores the cookies automatically if i dont override the configuration with my custom httpCookiesSession object. I am kind of lost here.



This is the URLSession call



   var configration = URLSessionConfiguration.default
//configration.httpCookieStorage = customHTTPCookiesStorage()

let session = URLSession.init(configuration: configration)



if let url = URL.init(string: "https://google.com"){
session.dataTask(with: url) { sip,sap,su in
print(sip,sap,su)

var x = session.configuration.httpCookieStorage?.cookies

}.resume()
}


This is the custom class



class customHTTPCookiesStorage: HTTPCookieStorage {

override func storeCookies(_ cookies: [HTTPCookie], for task: URLSessionTask) {

super.storeCookies(cookies, for: task)
for cookies in cookies{
session?.session.configuration.httpCookieStorage?.setCookie(cookies)
}

print("This is where cookies are stored")
}
}


Update 1
My aim is not to store the cookies in httpcookiesstore when Http response status in 401







ios swift alamofire urlsession nshttpcookiestorage






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 9:11







Hunble Dhillon

















asked Nov 22 '18 at 14:27









Hunble DhillonHunble Dhillon

713




713













  • And what happens when you set a breakpoint on the line that calls super.storeCookies(...)?

    – Caleb
    Nov 23 '18 at 5:09











  • so cookies are available, in the cookies variable. if I put a breakpoint. but never gets stored automatically. i am sure the for loop i have written in not required but even after successful iterations of for loop, httpcookiesstorage is empty, i was wondering if i am overriding the correct methods and if there is another elegant way of doing so. i just dont want to store cookies in when the status code in 401.

    – Hunble Dhillon
    Nov 23 '18 at 5:19













  • developer.apple.com/documentation/foundation/httpcookiestorage have a look at the subclassing section.

    – Hunble Dhillon
    Nov 23 '18 at 5:25













  • Why is configration.httpCookieStorage = customHTTPCookiesStorage() commented out?

    – Caleb
    Nov 23 '18 at 6:28











  • I commented that out to check if the cookies were being stored otherwise. and they were. I can upload the project in some public repo if you want to check that out?

    – Hunble Dhillon
    Nov 23 '18 at 6:49



















  • And what happens when you set a breakpoint on the line that calls super.storeCookies(...)?

    – Caleb
    Nov 23 '18 at 5:09











  • so cookies are available, in the cookies variable. if I put a breakpoint. but never gets stored automatically. i am sure the for loop i have written in not required but even after successful iterations of for loop, httpcookiesstorage is empty, i was wondering if i am overriding the correct methods and if there is another elegant way of doing so. i just dont want to store cookies in when the status code in 401.

    – Hunble Dhillon
    Nov 23 '18 at 5:19













  • developer.apple.com/documentation/foundation/httpcookiestorage have a look at the subclassing section.

    – Hunble Dhillon
    Nov 23 '18 at 5:25













  • Why is configration.httpCookieStorage = customHTTPCookiesStorage() commented out?

    – Caleb
    Nov 23 '18 at 6:28











  • I commented that out to check if the cookies were being stored otherwise. and they were. I can upload the project in some public repo if you want to check that out?

    – Hunble Dhillon
    Nov 23 '18 at 6:49

















And what happens when you set a breakpoint on the line that calls super.storeCookies(...)?

– Caleb
Nov 23 '18 at 5:09





And what happens when you set a breakpoint on the line that calls super.storeCookies(...)?

– Caleb
Nov 23 '18 at 5:09













so cookies are available, in the cookies variable. if I put a breakpoint. but never gets stored automatically. i am sure the for loop i have written in not required but even after successful iterations of for loop, httpcookiesstorage is empty, i was wondering if i am overriding the correct methods and if there is another elegant way of doing so. i just dont want to store cookies in when the status code in 401.

– Hunble Dhillon
Nov 23 '18 at 5:19







so cookies are available, in the cookies variable. if I put a breakpoint. but never gets stored automatically. i am sure the for loop i have written in not required but even after successful iterations of for loop, httpcookiesstorage is empty, i was wondering if i am overriding the correct methods and if there is another elegant way of doing so. i just dont want to store cookies in when the status code in 401.

– Hunble Dhillon
Nov 23 '18 at 5:19















developer.apple.com/documentation/foundation/httpcookiestorage have a look at the subclassing section.

– Hunble Dhillon
Nov 23 '18 at 5:25







developer.apple.com/documentation/foundation/httpcookiestorage have a look at the subclassing section.

– Hunble Dhillon
Nov 23 '18 at 5:25















Why is configration.httpCookieStorage = customHTTPCookiesStorage() commented out?

– Caleb
Nov 23 '18 at 6:28





Why is configration.httpCookieStorage = customHTTPCookiesStorage() commented out?

– Caleb
Nov 23 '18 at 6:28













I commented that out to check if the cookies were being stored otherwise. and they were. I can upload the project in some public repo if you want to check that out?

– Hunble Dhillon
Nov 23 '18 at 6:49





I commented that out to check if the cookies were being stored otherwise. and they were. I can upload the project in some public repo if you want to check that out?

– Hunble Dhillon
Nov 23 '18 at 6:49












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53433096%2fusing-httpscookiesstorage-can-i-screenfilter-cookies-storage-in-urlsession%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53433096%2fusing-httpscookiesstorage-can-i-screenfilter-cookies-storage-in-urlsession%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Create new schema in PostgreSQL using DBeaver

Deepest pit of an array with Javascript: test on Codility

Fotorealismo