I am using the AVAssetResourceLoadingDelegate
to intercept all manifest requests for an HLS Manifest
let str = "examplehttp://example.com/path/to/master.m3u8?token=SOMETOKEN"
guard let url = URL(string: str) else { return }
let asset = AVURLAsset(url: url)
let loaderQueue = DispatchQueue(label: "com.example.LoaderQueue")
asset.resourceLoader.setDelegate(delegate, queue: loaderQueue)
let item = AVPlayerItem(asset: asset)
player = AVPlayer(playerItem: item)
player?.playImmediately(atRate: 1.0)
In the delegate I perform all the manifest requests myself using URLSession
and return the responses back to the AVAssetResourceLoadingRequest
// NOTE: dataRequest: AVAssetResourceLoadingDataRequest
dataRequest.respond(with: data)
loadingRequest.response = response
loadingRequest.finishLoading()
This stream is protected using a fairly standard auth process:
Request to master manifest is made with an appended token query param. The response to the master manifest includes a set-cookie header. Each subsequent request that has a domain specified on the set-cookie response header includes the cookie on its request headers.
What I am finding is that all requests made through the delegate do have the cookie added to the header but since the delegate cannot be used for TS segments the cookie is not being added.
Does anyone know of a way to force the AVURLAsset
to always use the cookie header provided by the response to the master manifest for requests that are made outside of the AVAssetResourceLoaderDelegate
?
Since I do provide the URLResponse
back to AVAssetResourceLoadingRequest
and I know you can add cookies to a URLSession using the URLSessionConfiguration's httpShouldAccpetCookies
, httpCookieAcceptPolicy
, and httpCookieStorage
properties. I don't think this is outside the realm of possibilities.
I am also aware of the AVURLAssetHTTPCookiesKey
that can be added to the instantiation of the AVURLAasset
but I do not have the cookie until a master manifest request is made.
Response From Apple: