Skip to content

Commit

Permalink
feat: Optionally force HTTPS content URIs (shaka-project#3025)
Browse files Browse the repository at this point in the history
  • Loading branch information
Álvaro Velad Galván authored Dec 17, 2020
1 parent 2c07646 commit 207c235
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions demo/common/message_ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ shakaDemo.MessageIds = {
DRM_SECTION_HEADER: 'DEMO_DRM_SECTION_HEADER',
DURATION_BACKOFF: 'DEMO_DURATION_BACKOFF',
ENABLED: 'DEMO_ENABLED',
FORCE_HTTPS: 'DEMO_FORCE_HTTPS',
FORCE_TRANSMUX_TS: 'DEMO_FORCE_TRANSMUX_TS',
FUZZ_FACTOR: 'DEMO_FUZZ_FACTOR',
IGNORE_DASH_EMPTY_ADAPTATION_SET: 'DEMO_IGNORE_DASH_EMPTY_ADAPTATION_SET',
Expand Down
4 changes: 3 additions & 1 deletion demo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,9 @@ shakaDemo.Config = class {
.addBoolInput_(MessageIds.LOW_LATENCY,
'streaming.lowLatencyMode')
.addBoolInput_(MessageIds.AUTO_LOW_LATENCY,
'streaming.autoLowLatencyMode');
'streaming.autoLowLatencyMode')
.addBoolInput_(MessageIds.FORCE_HTTPS,
'streaming.forceHTTPS');

if (!shakaDemoMain.getNativeControlsEnabled()) {
this.addBoolInput_(MessageIds.ALWAYS_STREAM_TEXT,
Expand Down
1 change: 1 addition & 0 deletions demo/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"DEMO_EDIT_CUSTOM": "Edit",
"DEMO_ENABLED": "Enabled",
"DEMO_FAIRPLAY": "Fairplay DRM",
"DEMO_FORCE_HTTPS": "Force HTTPS",
"DEMO_FORCE_TRANSMUX_TS": "Force Transmux TS",
"DEMO_FRONT_INTRO_DISMISS": "Dismiss",
"DEMO_FRONT_INTRO_ONE": "This is a demo of Google's Shaka Player, a JavaScript library for adaptive video streaming.",
Expand Down
4 changes: 4 additions & 0 deletions demo/locales/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@
"description": "Text that describes an asset that is protected with the Fairplay Digital Rights Management system.",
"message": "[PROPER_NAME:Fairplay] [JARGON:DRM]"
},
"DEMO_FORCE_HTTPS": {
"description": "The name of a configuration value.",
"message": "Force [JARGON:HTTPS]"
},
"DEMO_FORCE_TRANSMUX_TS": {
"description": "The name of a configuration value.",
"message": "Force Transmux [JARGON:MPEG-2 TS]"
Expand Down
5 changes: 4 additions & 1 deletion externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,8 @@ shaka.extern.ManifestConfiguration;
* useNativeHlsOnSafari: boolean,
* inaccurateManifestTolerance: number,
* lowLatencyMode: boolean,
* autoLowLatencyMode: boolean
* autoLowLatencyMode: boolean,
* forceHTTPS: boolean
* }}
*
* @description
Expand Down Expand Up @@ -828,6 +829,8 @@ shaka.extern.ManifestConfiguration;
* lowLatencyMode, but if it has been configured to activate the
* lowLatencyMode if a stream of this type is detected, we automatically
* activate the lowLatencyMode. Defaults to false.
* @property {boolean} forceHTTPS
* If true, if the protocol is HTTP change it to HTTPs.
*
* @exportDoc
*/
Expand Down
15 changes: 15 additions & 0 deletions lib/net/networking_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ shaka.net.NetworkingEngine = class extends shaka.util.FakeEventTarget {

/** @private {?function(number, number)} */
this.onProgressUpdated_ = onProgressUpdated || null;

/** @private {boolean} */
this.forceHTTPS_ = false;
}

/**
* @param {boolean} forceHTTPS
* @export
*/
setForceHTTPS(forceHTTPS) {
this.forceHTTPS_ = forceHTTPS;
}

/**
Expand Down Expand Up @@ -380,6 +391,10 @@ shaka.net.NetworkingEngine = class extends shaka.util.FakeEventTarget {
* @private
*/
send_(type, request, backoff, index, lastError, numBytesRemainingObj) {
if (this.forceHTTPS_) {
request.uris[index] = request.uris[index].replace('http://', 'https://');
}

const uri = new goog.Uri(request.uris[index]);
let scheme = uri.getScheme();
// Whether it got a progress event.
Expand Down
4 changes: 4 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
}

this.networkingEngine_ = this.createNetworkingEngine();
this.networkingEngine_.setForceHTTPS(this.config_.streaming.forceHTTPS);

/** @private {shaka.extern.IAdManager} */
this.adManager_ = null;
Expand Down Expand Up @@ -2716,6 +2717,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
}
}
}
if (this.networkingEngine_) {
this.networkingEngine_.setForceHTTPS(this.config_.streaming.forceHTTPS);
}

if (this.mediaSourceEngine_) {
const textDisplayerFactory = this.config_.textDisplayFactory;
Expand Down
1 change: 1 addition & 0 deletions lib/util/player_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ shaka.util.PlayerConfiguration = class {
inaccurateManifestTolerance: 2,
lowLatencyMode: false,
autoLowLatencyMode: false,
forceHTTPS: false,
};

// WebOS, Tizen, and Chromecast have long hardware pipelines that respond
Expand Down
3 changes: 3 additions & 0 deletions test/test/util/fake_networking_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ shaka.test.FakeNetworkingEngine = class {
/** @private {?shaka.extern.ResponseFilter} */
this.responseFilter_ = null;

/** @type {!jasmine.Spy} */
this.setForceHTTPS = jasmine.createSpy('setForceHTTPS').and.stub();

// The prototype has already been applied; create spies for the
// methods but still call it by default.
spyOn(this, 'destroy').and.callThrough();
Expand Down

0 comments on commit 207c235

Please sign in to comment.