Skip to content

Commit

Permalink
[Blobs] Correctly set mimetype of blob in FetchDataLoader.
Browse files Browse the repository at this point in the history
Just creating a new BlobDataHandle doesn't actually update the mimetype
of the blob (if later the blob is requested through a blob: URL for
example), so instead actually create a new blob wrapping the existing
blob to properly change the mimetype.

Bug: none
Change-Id: I93b6d584178a02a74d68bdd6fcace1514ca90ec0
  • Loading branch information
mkruisselbrink authored and chromium-wpt-export-bot committed Mar 19, 2018
1 parent 2667757 commit 8a48e67
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions fetch/api/response/response-consume.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
});
}

function blobToTypeViaFetch(blob) {
var url = URL.createObjectURL(blob);
return fetch(url).then(function(response) {
return response.headers.get('Content-Type');
});
}

function responsePromise(body, responseInit) {
return new Promise(function(resolve, reject) {
resolve(new Response(body, responseInit));
Expand Down Expand Up @@ -75,15 +82,18 @@
return response.blob().then(function(bodyAsBlob) {
assert_equals(bodyAsBlob.type, expectedType || "text/plain", "Blob body type should be computed from the response Content-Type");

var promise = new Promise( function (resolve, reject) {
var reader = new FileReader();
reader.onload = function(evt) {
resolve(reader.result)
};
reader.onerror = function () {
reject("Blob's reader failed");
};
reader.readAsText(bodyAsBlob);
var promise = blobToTypeViaFetch(bodyAsBlob).then(function(type) {
assert_equals(type, expectedType || "text/plain", 'Type via blob URL');
return new Promise( function (resolve, reject) {
var reader = new FileReader();
reader.onload = function(evt) {
resolve(reader.result)
};
reader.onerror = function () {
reject("Blob's reader failed");
};
reader.readAsText(bodyAsBlob);
});
});
return promise.then(function(body) {
assert_equals(body, expectedBody, "Retrieve and verify response's body");
Expand Down

0 comments on commit 8a48e67

Please sign in to comment.