Skip to content

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

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

Open
sebsto opened this issue May 23, 2025 · 0 comments
Open

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

sebsto opened this issue May 23, 2025 · 0 comments

Comments

@sebsto
Copy link

sebsto commented May 23, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant