I am starting a request in a WKWebView on the iOS 9.3 simulator

    let url = NSURL(string:"http://localhost:8000/";)
    let req = NSMutableURLRequest(URL:url!)
    webView.loadRequest(req)

and intercept the response where I try to print out the cookies

    func webView(webView: WKWebView, decidePolicyForNavigationResponse
navigationResponse: WKNavigationResponse, decisionHandler:
(WKNavigationResponsePolicy) -> Void) {
        if let httpResponse = navigationResponse.response as?
NSHTTPURLResponse {
            if let headers = httpResponse.allHeaderFields as? [String:
String], url = httpResponse.URL {
                NSLog("cookies for %@", url)
                let cookies =
NSHTTPCookie.cookiesWithResponseHeaderFields(headers, forURL: url)
                for cookie in cookies {
                    NSLog(cookie.description)
                    NSLog("found cookie " + cookie.name + " " +
cookie.value)
                }
                NSLog("cookies for %@ done", url)
            }
        }
        decisionHandler(WKNavigationResponsePolicy.Allow)
    }

The first request is to show a form - no cookies

    GET /
    cookies for http://localhost:8000/
    cookies for http://localhost:8000/ done

The POST then triggers the backend to set one

    POST /
    Set-Cookie: remember=1; Max-Age=300; Path=/; Expires=Tue, 12 Apr 2016
08:56:41 GMT
    cookies for http://localhost:8000/
    cookies for http://localhost:8000/ done

but I still cannot see the cookie on the client.

If I now restart the app the cookie is sent

    GET /
    Cookie: remember=1

and the backend confirms that the cookie is set - but I still can't see it
from the WKWebView.

    cookies for http://localhost:8000/
    cookies for http://localhost:8000/ done

I also tried to find it in the cookie storage

    NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies!

but that does not seem to have it either.

After lots of reading of StackOverflow and searching the mailing list
archives I am left a bit puzzled.
What am I missing here?

cheers,
Torsten
_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to