AVURLAsset with AVURLAssetHTTPCookiesKey - Cookies not persisting on retry requests

I'm experiencing an unexpected behavior with AVURLAsset and cookies. When setting cookies through AVURLAssetHTTPCookiesKey option, they seem to be sent only on the initial request but not on retry attempts.

Here's my current implementation:

let cookieProperties: [HTTPCookiePropertyKey: Any] = [
  .name: "sessionCookie",
  .value: "testValue",
  .domain: url.host ?? "",
  .path: "/",
  .secure: true
]
if let cookie = HTTPCookie(properties: cookieProperties) {
  let asset = AVURLAsset(url: url, options: [
    AVURLAssetHTTPCookiesKey: [cookie],
  ])
}

According to the documentation, AVURLAssetHTTPCookiesKey should apply the cookies to all requests made by this asset. However, when the initial request fails and AVPlayer retries, the cookies are not included in subsequent requests.

Only when I store the cookie with HTTPCookieStorage.shared.setCookie, then it persists.

Questions:

  1. Is this the expected behavior?
  2. If not, what could be causing the cookies to not persist for retry attempts?
  3. Is using HTTPCookieStorage.shared the recommended approach instead?

Environment:

  • iOS 16+
  • Using AVPlayer with AVURLAsset
  • Streaming HLS content

Any insights would be greatly appreciated.

AVURLAsset with AVURLAssetHTTPCookiesKey - Cookies not persisting on retry requests
 
 
Q