Skip to content

[Compatibility] HTTPCookie does not accept URL as String #5217

Open
@sebsto

Description

@sebsto

This code works on macOS but produces nil on Linux.

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

let url = "https://dummy.com/"
let cookie = HTTPCookie(properties: [.name: "cookieName", .value: "cookieValue", .path: "/", .originURL: url])

//cookie == nil here on Linux

The root cause is that HTTPCookie(properties:) happily accepts a String for .originURL with Foundation but only accepts an URL with FoundationNetworking.

This code works both on macOS and Linux

let url = URL(string: "https://dummy.com/")!
let cookie = HTTPCookie(properties: [.name: "cookieName", .value: "cookieValue", .path: "/", .originURL: url])

//cookie != nil here on Linux and macOS

According to @Lukasa, this is probably a compatibility bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions