Skip to content

Commit

Permalink
Fix/content steering host (#4213)
Browse files Browse the repository at this point in the history
* Add protocol to pathway cloning host url in case it is not defined.
  • Loading branch information
dsilhavy committed Jun 16, 2023
1 parent ed9d083 commit 62ea37b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/core/Utils.js
Expand Up @@ -145,8 +145,8 @@ class Utils {

/**
* Compares both urls and returns a relative url (target relative to original)
* @param {string} original
* @param {string} target
* @param {string} originalUrl
* @param {string} targetUrl
* @return {string|*}
*/
static getRelativeUrl(originalUrl, targetUrl) {
Expand Down Expand Up @@ -187,6 +187,15 @@ class Utils {
return {};
}
}

/**
* Checks for existence of "http" or "https" in a string
* @param string
* @returns {boolean}
*/
static stringHasProtocol(string) {
return (/(http(s?)):\/\//i.test(string))
}
}

export default Utils;
6 changes: 4 additions & 2 deletions src/dash/controllers/ContentSteeringController.js
Expand Up @@ -36,10 +36,10 @@ import ContentSteeringRequest from '../vo/ContentSteeringRequest';
import ContentSteeringResponse from '../vo/ContentSteeringResponse';
import DashConstants from '../constants/DashConstants';
import MediaPlayerEvents from '../../streaming/MediaPlayerEvents';
import Utils from '../../core/Utils';
import URLUtils from '../../streaming/utils/URLUtils';
import BaseURL from '../vo/BaseURL';
import MpdLocation from '../vo/MpdLocation';
import Utils from '../../core/Utils.js';

const QUERY_PARAMETER_KEYS = {
THROUGHPUT: '_DASH_throughput',
Expand Down Expand Up @@ -486,9 +486,11 @@ function ContentSteeringController() {
}
if (reference) {
const referenceUrl = new URL(reference.url);
let host = pathwayClone[DashConstants.CONTENT_STEERING_RESPONSE.URI_REPLACEMENT][DashConstants.CONTENT_STEERING_RESPONSE.HOST];
host = Utils.stringHasProtocol(host) ? host : `${referenceUrl.protocol}//${host}`;
const synthesizedElement =
{
synthesizedUrl: `${pathwayClone[DashConstants.CONTENT_STEERING_RESPONSE.URI_REPLACEMENT][DashConstants.CONTENT_STEERING_RESPONSE.HOST]}${referenceUrl.pathname}`,
synthesizedUrl: `${host}${referenceUrl.pathname}`,
serviceLocation: pathwayClone[DashConstants.CONTENT_STEERING_RESPONSE.ID],
queryParams: pathwayClone[DashConstants.CONTENT_STEERING_RESPONSE.URI_REPLACEMENT][DashConstants.CONTENT_STEERING_RESPONSE.PARAMS],
reference
Expand Down
15 changes: 15 additions & 0 deletions test/unit/core.Utils.js
Expand Up @@ -94,4 +94,19 @@ describe('Utils', () => {
expect(Utils.parseHttpHeaders(null)).to.be.empty;
})
})

describe('stringHasProtocol', () => {

it('Should return true for valid http url', () => {
expect(Utils.stringHasProtocol('http://dash.akamaized.net')).to.be.true;
})

it('Should return true for valid https url', () => {
expect(Utils.stringHasProtocol('https://dash.akamaized.net')).to.be.true;
})

it('Should return false if url has no protocol', () => {
expect(Utils.stringHasProtocol('dash.akamaized.net')).to.be.false;
})
})
})

0 comments on commit 62ea37b

Please sign in to comment.