Swift HTTPCookie setHttpOnly

Hi there, I'm currently initializing a cookie that is supposed to be http only for the security purposes. However, I can't find a way to set the cookie to be http only. Could anyone point me to the right direciton?

let cookie = HTTPCookie(properties: [

        .domain: "aaa.bbbb.ccc",

        .path: "/",

        .name: "token",

        .value: "aaa.bbb.ccc",

        .version: 1,

        .secure: true,

        .expires: NSDate(timeIntervalSinceNow: 12345)

    ])!

I think your best option here is to use a raw value:

let c = HTTPCookie(properties: [
    .domain: "aaa.bbbb.ccc",
    .path: "/",
    .name: "token",
    .value: "aaa.bbb.ccc",
    .version: 1,
    .secure: true,
    .expires: NSDate(timeIntervalSinceNow: 12345),
    .init(rawValue: "HttpOnly"): true
])!
print(c.isHTTPOnly) // true

I’d appreciate you filing a bug against HTTPCookiePropertyKey requesting that we define a constant for this. Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Swift HTTPCookie setHttpOnly
 
 
Q