Skip to content

Commit

Permalink
Merge pull request #266 from rgc/redirect-fix
Browse files Browse the repository at this point in the history
Add support for 302 redirect
  • Loading branch information
joeyparrish committed Jan 14, 2016
2 parents 471ddd7 + 471a950 commit f21a725
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 8 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Jesper Haug Karsrud <[email protected]>
Nick Desaulniers <[email protected]>
Oskar Arvidsson <[email protected]>
Philo Inc. <*@philo.com>
Robert Colantuoni <[email protected]>
Roi Lipman <[email protected]>
Sanborn Hilland <[email protected]>
TalkTalk Plc <*@talktalkplc.com>
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Jono Ward <[email protected]>
Natalie Harris <[email protected]>
Nick Desaulniers <[email protected]>
Oskar Arvidsson <[email protected]>
Robert Colantuoni <[email protected]>
Rohit Makasana <[email protected]>
Roi Lipman <[email protected]>
Sanborn Hilland <[email protected]>
Expand Down
12 changes: 8 additions & 4 deletions lib/dash/mpd_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ goog.require('shaka.util.Uint8ArrayUtils');
* Numbers, times, and byte ranges are set to null if they cannot be parsed.
*
* @param {string} source The MPD XML text.
* @param {!Array.<!goog.Uri>} url The MPD URL for relative BaseURL resolution.
* @param {!Array.<!goog.Uri>} origUrl MPD URL for original download location.
* @param {!Array.<!goog.Uri>} baseUrl MPD URL for relative BaseURL resolution.
* @return {shaka.dash.mpd.Mpd}
*
* @see ISO/IEC 23009-1
*/
shaka.dash.mpd.parseMpd = function(source, url) {
shaka.dash.mpd.parseMpd = function(source, origUrl, baseUrl) {
var parser = new DOMParser();
var xml = parser.parseFromString(source, 'text/xml');

Expand All @@ -51,7 +52,7 @@ shaka.dash.mpd.parseMpd = function(source, url) {
}

// Construct a virtual parent for the MPD to use in resolving relative URLs.
var parent = { baseUrl: url };
var parent = { origUrl: origUrl, baseUrl: baseUrl };

return shaka.dash.mpd.parseChild_(parent, xml, shaka.dash.mpd.Mpd);
};
Expand Down Expand Up @@ -89,6 +90,9 @@ shaka.dash.mpd.Mpd = function() {
/** @type {string} */
this.type = 'static';

/** @type {Array.<!goog.Uri>} */
this.origUrl = null;

/** @type {Array.<!goog.Uri>} */
this.baseUrl = null;

Expand Down Expand Up @@ -869,7 +873,7 @@ shaka.dash.mpd.Mpd.prototype.parse = function(parent, elem) {
var mpd = shaka.dash.mpd;

// Parse attributes.
this.url = parent.baseUrl;
this.url = parent.origUrl;
this.id = mpd.parseAttr_(elem, 'id', mpd.parseString_);
this.type = mpd.parseAttr_(elem, 'type', mpd.parseString_) || 'static';
this.mediaPresentationDuration = mpd.parseAttr_(
Expand Down
2 changes: 1 addition & 1 deletion lib/dash/mpd_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ shaka.dash.MpdRequest.prototype.send = function() {
/** @param {!ArrayBuffer|string} data */
function(data) {
var mpd = shaka.dash.mpd.parseMpd(
/** @type {string} */ (data), url.urls);
/** @type {string} */ (data), url.urls, [url.currentUrl]);
if (mpd) {
return Promise.resolve(mpd);
}
Expand Down
10 changes: 10 additions & 0 deletions lib/util/failover_uri.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ shaka.util.FailoverUri = function(callback, urls, opt_startByte, opt_endByte) {

/** @private {shaka.util.FailoverUri.NetworkCallback} */
this.callback_ = callback;

/** @type {goog.Uri} */
this.currentUrl = null;
};


Expand Down Expand Up @@ -134,6 +137,7 @@ shaka.util.FailoverUri.prototype.abortFetch = function() {
this.requestPromise_ = null;
this.request_.abort();
this.request_ = null;
this.currentUrl = null;
}
};

Expand Down Expand Up @@ -168,6 +172,12 @@ shaka.util.FailoverUri.prototype.createRequest_ =
// effectively cache every response.
this.requestPromise_ = null;
this.request_ = null;
this.currentUrl = null;
if (xhr.responseURL) {
this.currentUrl = new goog.Uri(xhr.responseURL);
} else {
this.currentUrl = this.urls[i];
}
return Promise.resolve(xhr.response);
}));

Expand Down
4 changes: 3 additions & 1 deletion spec/mpd_parser_base_url_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ describe('mpd.BaseUrl', function() {
'</MPD>'].join('\n');
var mpdUrl = 'http://example.com/dash/test.mpd';

var mpd = shaka.dash.mpd.parseMpd(source, createFailover(mpdUrl).urls);
var mpd = shaka.dash.mpd.parseMpd(source,
createFailover(mpdUrl).urls,
createFailover(mpdUrl).urls);
expect(mpd).toBeTruthy();
expect(mpd.baseUrl.toString()).toBe(mpdUrl);
expect(mpd.periods.length).toBe(1);
Expand Down
5 changes: 3 additions & 2 deletions spec/mpd_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,9 @@ describe('mpd', function() {
' <Location>updated_mpd</Location>',
'</MPD>'].join('\n');

var mpd = shaka.dash.mpd.parseMpd(source, createFailover(
'http://example.com/mpd').urls);
var mpd = shaka.dash.mpd.parseMpd(source,
createFailover('http://example.com/mpd').urls,
createFailover('http://example.com/mpd').urls);
expect(mpd.updateLocation.toString()).toBe(
'http://example.com/updated_mpd');
});
Expand Down

0 comments on commit f21a725

Please sign in to comment.