Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix when using Data URIs for the manifest #550

Merged
merged 3 commits into from
Oct 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Jason Palmer <[email protected]>
Jesper Haug Karsrud <[email protected]>
Johan Sundström <[email protected]>
JW Player <*@jwplayer.com>
Lucas Gabriel Sánchez <[email protected]>
Mattias Wadman <[email protected]>
Nick Desaulniers <[email protected]>
Oskar Arvidsson <[email protected]>
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Jesper Haug Karsrud <[email protected]>
Joey Parrish <[email protected]>
Johan Sundström <[email protected]>
Jono Ward <[email protected]>
Lucas Gabriel Sánchez <[email protected]>
Mattias Wadman <[email protected]>
Natalie Harris <[email protected]>
Nick Desaulniers <[email protected]>
Expand Down
9 changes: 8 additions & 1 deletion lib/net/data_uri_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,14 @@ shaka.net.DataUriPlugin = function(uri, request) {
}

/** @type {shakaExtern.Response} */
var response = {uri: uri, data: data, headers: {}};
var response = {
uri: uri,
data: data,
headers: {
'content-type': typeAndEncoding[0]
}
};

resolve(response);
});
};
Expand Down
14 changes: 8 additions & 6 deletions test/net/data_uri_plugin_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,32 @@ describe('DataUriPlugin', function() {
});

it('supports MIME types', function(done) {
testSucceeds('data:text/plain,Hello', 'Hello', done);
testSucceeds('data:text/plain,Hello', 'text/plain', 'Hello', done);
});

it('supports URI encoded text', function(done) {
testSucceeds(
'data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E',
'text/html',
'<h1>Hello, World!</h1>',
done);
});

it('supports base64 encoded text', function(done) {
testSucceeds(
'data:;base64,SGVsbG8sIFdvcmxkIQ%3D%3D', 'Hello, World!', done);
'data:;base64,SGVsbG8sIFdvcmxkIQ%3D%3D', '', 'Hello, World!', done);
});

it('supports extra colin', function(done) {
testSucceeds('data:,Hello:', 'Hello:', done);
testSucceeds('data:,Hello:', '', 'Hello:', done);
});

it('supports extra semi-colin', function(done) {
testSucceeds('data:,Hello;', 'Hello;', done);
testSucceeds('data:,Hello;', '', 'Hello;', done);
});

it('supports extra comma', function(done) {
testSucceeds('data:,Hello,', 'Hello,', done);
testSucceeds('data:,Hello,', '', 'Hello,', done);
});

it('fails for empty URI', function(done) {
Expand All @@ -67,14 +68,15 @@ describe('DataUriPlugin', function() {
testFails('data:Bad', done, shaka.util.Error.Code.MALFORMED_DATA_URI);
});

function testSucceeds(uri, text, done) {
function testSucceeds(uri, contentType, text, done) {
var request =
shaka.net.NetworkingEngine.makeRequest([uri], retryParameters);
shaka.net.DataUriPlugin(uri, request)
.then(function(response) {
expect(response).toBeTruthy();
expect(response.uri).toBe(uri);
expect(response.data).toBeTruthy();
expect(response.headers['content-type']).toBe(contentType);
var data = shaka.util.StringUtils.fromBytesAutoDetect(response.data);
expect(data).toBe(text);
})
Expand Down