title: Request to HLS/DASH URL for Reddit-hosted video through XHR results in “CORS header ‘Access-Control-Allow-Origin’ missing” error
body: <p>I'm trying to use the hls.js library for displaying Reddit hosted videos from the HLS/DASH playlist. However, accessing any Reddit HLS/DASH url, such as <a href="https://v.redd.it/5r0nz8sywgl41/DASHPlaylist.mpd" rel="nofollow noreferrer">this one</a> through XHR will fail due to, what the error says is a Same Origin Policy violation:</p>
  
  <p><code>Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://v.redd.it/5r0nz8sywgl41/DASHPlaylist.mpd. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).</code></p>
  
  <p>Weird thing is, the request prior GET is an OPTIONS one, which does return the Access-Control-Allow-Origin header with the correct origin url. I can see the response in the developer console, but the request still "fails". If I use the "Allow CORS: Access-Control-Allow-Origin" extension, everything works fine. <strong>What am I doing incorrectly?</strong></p>
  
  <p>OPTIONS request headers:</p>
  
  <pre><code>Host: v.redd.it
  User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:73.0) Gecko/20100101 Firefox/73.0
  Accept: */*
  Accept-Language: lt,en-US;q=0.7,en;q=0.3
  Accept-Encoding: gzip, deflate, br
  Access-Control-Request-Method: GET
  Access-Control-Request-Headers: authorization
  Referer: http://localhost:3000/
  Origin: http://localhost:3000
  DNT: 1
  Connection: keep-alive
  Save-Data: on
  Pragma: no-cache
  Cache-Control: no-cache
  TE: Trailers
  </code></pre>
  
  <p>OPTIONS response headers: </p>
  
  <pre><code>HTTP/2 200 OK
  retry-after: 0
  access-control-allow-origin: http://localhost:3000
  access-control-allow-headers: authorization
  access-control-allow-methods: GET
  access-control-max-age: 3000
  date: Sun, 08 Mar 2020 18:40:29 GMT
  via: 1.1 varnish
  x-served-by: cache-hhn4029-HHN
  x-cache: HIT
  x-cache-hits: 0
  x-timer: S1583692829.044409,VS0,VE0
  server: snooserv
  accept-ranges: bytes
  x-cdn-server-region: EU-East
  x-cdn-client-region: EU
  x-cdn-name: fastly
  access-control-expose-headers: x-cdn-server-region, x-cdn-client-region, x-cdn-name
  cache-control: public, max-age=604800, s-maxage=86400, must-revalidate
  vary: Access-Control-Request-Headers, Access-Control-Request-Method,Origin
  content-length: 0
  X-Firefox-Spdy: h2
  </code></pre>
  
  <p>GET request headers:</p>
  
  <pre><code>Host: v.redd.it
  User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:73.0) Gecko/20100101 Firefox/73.0
  Accept: */*
  Accept-Language: lt,en-US;q=0.7,en;q=0.3
  Accept-Encoding: gzip, deflate, br
  Referer: http://localhost:3000/
  Authorization: Bearer --------------------------- (actual token here)
  Origin: http://localhost:3000
  DNT: 1
  Connection: keep-alive
  Save-Data: on
  Pragma: no-cache
  Cache-Control: no-cache
  TE: Trailers
  </code></pre>
  
  <p>GET response headers:</p>
  
  <pre><code>HTTP/2 200 OK
  last-modified: Sun, 08 Mar 2020 15:34:11 GMT
  etag: "0abfb243cb8d03188bf34ff29d6d4af8"
  content-type: application/dash+xml
  via: 1.1 varnish
  date: Sun, 08 Mar 2020 18:40:29 GMT
  via: 1.1 varnish
  x-served-by: cache-bwi5138-BWI, cache-hhn4029-HHN
  x-cache: HIT, HIT
  x-cache-hits: 2, 34
  x-timer: S1583692829.127808,VS0,VE0
  server: snooserv
  accept-ranges: bytes
  x-cdn-server-region: EU-East
  x-cdn-client-region: EU
  x-cdn-name: fastly
  access-control-expose-headers: x-cdn-server-region, x-cdn-client-region, x-cdn-name
  cache-control: public, max-age=604800, s-maxage=86400, must-revalidate
  vary: Origin
  content-length: 1976
  X-Firefox-Spdy: h2
  </code></pre>
  
  <p>GET response:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;MPD mediaPresentationDuration="PT15.034S" minBufferTime="PT1.500S" profiles="urn:mpeg:dash:profile:isoff-on-demand:2011" type="static" xmlns="urn:mpeg:dash:schema:mpd:2011"&gt;
      &lt;Period duration="PT15.034S"&gt;
          &lt;AdaptationSet segmentAlignment="true" subsegmentAlignment="true" subsegmentStartsWithSAP="1"&gt;
              &lt;Representation bandwidth="1172841" codecs="avc1.4d401f" frameRate="30" height="480" id="VIDEO-1" mimeType="video/mp4" startWithSAP="1" width="720"&gt;
                  &lt;BaseURL&gt;DASH_480&lt;/BaseURL&gt;
                  &lt;SegmentBase indexRange="913-992" indexRangeExact="true"&gt;
                      &lt;Initialization range="0-912"/&gt;
                  &lt;/SegmentBase&gt;
              &lt;/Representation&gt;
              &lt;Representation bandwidth="784684" codecs="avc1.4d401e" frameRate="30" height="360" id="VIDEO-2" mimeType="video/mp4" startWithSAP="1" width="540"&gt;
                  &lt;BaseURL&gt;DASH_360&lt;/BaseURL&gt;
                  &lt;SegmentBase indexRange="915-994" indexRangeExact="true"&gt;
                      &lt;Initialization range="0-914"/&gt;
                  &lt;/SegmentBase&gt;
              &lt;/Representation&gt;
              &lt;Representation bandwidth="592784" codecs="avc1.4d401e" frameRate="30" height="240" id="VIDEO-3" mimeType="video/mp4" startWithSAP="1" width="360"&gt;
                  &lt;BaseURL&gt;DASH_240&lt;/BaseURL&gt;
                  &lt;SegmentBase indexRange="915-994" indexRangeExact="true"&gt;
                      &lt;Initialization range="0-914"/&gt;
                  &lt;/SegmentBase&gt;
              &lt;/Representation&gt;
              &lt;Representation bandwidth="91690" codecs="avc1.4d400a" frameRate="30" height="96" id="VIDEO-4" mimeType="video/mp4" startWithSAP="1" width="144"&gt;
                  &lt;BaseURL&gt;DASH_96&lt;/BaseURL&gt;
                  &lt;SegmentBase indexRange="912-991" indexRangeExact="true"&gt;
                      &lt;Initialization range="0-911"/&gt;
                  &lt;/SegmentBase&gt;
              &lt;/Representation&gt;
          &lt;/AdaptationSet&gt;
      &lt;/Period&gt;
  &lt;/MPD&gt;
  </code></pre>
  
  <p>Thanks a lot for your help.</p>