UNPKG

916 BJavaScriptView Raw
1/**
2 * @file resolve-url.js - Handling how URLs are resolved and manipulated
3 */
4
5import _resolveUrl from '@videojs/vhs-utils/es/resolve-url.js';
6
7export const resolveUrl = _resolveUrl;
8
9/**
10 * Checks whether xhr request was redirected and returns correct url depending
11 * on `handleManifestRedirects` option
12 *
13 * @api private
14 *
15 * @param {string} url - an url being requested
16 * @param {XMLHttpRequest} req - xhr request result
17 *
18 * @return {string}
19 */
20export const resolveManifestRedirect = (handleManifestRedirect, url, req) => {
21 // To understand how the responseURL below is set and generated:
22 // - https://fetch.spec.whatwg.org/#concept-response-url
23 // - https://fetch.spec.whatwg.org/#atomic-http-redirect-handling
24 if (
25 handleManifestRedirect &&
26 req &&
27 req.responseURL &&
28 url !== req.responseURL
29 ) {
30 return req.responseURL;
31 }
32
33 return url;
34};
35
36export default resolveUrl;