title: AVPlayer making extraneous http request prior to playback of HLS / AES-encrypted video
body: <p>We're using AVPlayer on iOS 8.4 to play HLS, AES-encrypted video.</p>
  <p>Our .m3u8 files include the url of the license server, e.g.:</p>
  <h1>EXT-X-KEY:METHOD=AES-128,URI=&quot;https://....&quot;</h1>
  <p>In our iOS application, we're using AVAssetResourceLoaderDelegate method
  resourceLoader:shouldWaitForLoadingOfRequestedResource:
  to intercept the request that gets sent by the AVPlayer (or some object within AVFoundation) to the license server. Within that method, we add a token (required by the license server) to the request's queryString.</p>
  <p>The license server receives the request with the token, returns the encryption key, and playback begins.
  In other words, everything works as expected.</p>
  <p><strong>However</strong>, we're noticing (using the &quot;Charles&quot; http monitor) that following the creation of the AVPlayerItem and prior to the invocation of the resourceLoader: method, AVFoundation <strong>sends an initial request to the license server url; a request that's not &quot;routed&quot; through method resourceLoader:</strong>. This request is rejected at the server as our iOS code never has a chance to append the token before the request goes out.</p>
  <p>Summary of events:</p>
  <p>• AVPlayerItem/AVAsset is created and initialized with the url of the .m3u8 index file.</p>
  <p>• Something within the AVFoundation framwork makes a request to the license server specified in the .m3u8 file. This <strong>initial request is NOT intercepted by method  recourceLoader:shouldWaitForLoadingOfRequestedResource:</strong> and the unmodified request hits the license server.  Because the request doesn't contain a required token in the queryString, it fails and no encrypton key is returned.</p>
  <p>• <strong>A second request is made by AVFoundation</strong> to the licesnse server. This request IS caught by recourceLoader:...and modified appropriately. The license server returns an encryption key and playback begins.</p>
  <p>This behavior can be replicated using Apple's AVARLDelegateDemo app.</p>
  <p><strong>Questions:</strong></p>
  <p>Is the initial http request sent by AVFoundation normal?</p>
  <p>If so, why is it necessary and why isn't it getting &quot;routed&quot; through the resourceLoader: method?</p>
  <p>Is it possible to suppress the initial request or modify it before it's sent?</p>
  <p>Thank you!</p>