From 5711e43d63f8933207381c92ea79aaac777af67d Mon Sep 17 00:00:00 2001 From: Jason D'Netto Date: Mon, 23 Jul 2018 13:33:35 +1000 Subject: [PATCH 1/3] HTTP 202 Accepted --- Source/Core/Resource.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Source/Core/Resource.js b/Source/Core/Resource.js index 6591265f24e6..df3794a9142e 100644 --- a/Source/Core/Resource.js +++ b/Source/Core/Resource.js @@ -1260,7 +1260,11 @@ define([ var timeout = options.timeout; var data = options.data; var deferred = when.defer(); +<<<<<<< Updated upstream var xhr = Resource._Implementations.loadWithXhr(resource.url, responseType, method, data, headers, deferred, overrideMimeType, timeout); +======= + var xhr = Resource._Implementations.loadWithXhr(resource.url, responseType, method, data, headers, deferred, overrideMimeType, request); +>>>>>>> Stashed changes if (defined(xhr) && defined(xhr.abort)) { request.cancelFunction = function() { xhr.abort(); @@ -1893,7 +1897,11 @@ define([ }).end(); } +<<<<<<< Updated upstream Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType, timeout) { +======= + Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType, request) { +>>>>>>> Stashed changes var dataUriRegexResult = dataUriRegex.exec(url); if (dataUriRegexResult !== null) { deferred.resolve(decodeDataUri(dataUriRegexResult, responseType)); @@ -1969,6 +1977,31 @@ define([ if (xhr.status === 204) { // accept no content deferred.resolve(); + } else if (xhr.status === 202) { + //HTTP 202 is for a process that can take a while + //contains at minimum a location to get the + //completed resource from + //and the permission to read the location + var newURL = xhr.getResponseHeader('Location'); + if (newURL === undefined || newURL === null || newURL === "") { + deferred.reject(new RuntimeError("HTTP 202 header with no Location.\n Contact the service owner directly about this misconfiguration.\n Using HTTP 202 responses requires 'Location' and 'Access-Control-Expose-Headers: Location' headers in the response")); + return; + } + //if request still valid change url and call this function + if (!request.cancelled) { + var newXHR; + setTimeout(function(){ + if (!request.cancelled){ + newXHR = loadWithXhr.load.call(this,newURL, responseType, method, data, headers, deferred, overrideMimeType, timeout, request); + } else { + //user cancel request after waking from sleep + return; + } + },10000); + return newXHR + } else { + return;//request has been cancelled by user before sleep + } } else if (defined(xhr.response) && (!defined(responseType) || (browserResponseType === responseType))) { deferred.resolve(response); } else if ((responseType === 'json') && typeof response === 'string') { From d22b8caaed8803402972f0d231b953b95fa224a2 Mon Sep 17 00:00:00 2001 From: Jason D'Netto Date: Mon, 23 Jul 2018 16:04:13 +1000 Subject: [PATCH 2/3] Resolve consflict --- Source/Core/Resource.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/Source/Core/Resource.js b/Source/Core/Resource.js index df3794a9142e..cfb37c7366d7 100644 --- a/Source/Core/Resource.js +++ b/Source/Core/Resource.js @@ -1260,14 +1260,11 @@ define([ var timeout = options.timeout; var data = options.data; var deferred = when.defer(); -<<<<<<< Updated upstream - var xhr = Resource._Implementations.loadWithXhr(resource.url, responseType, method, data, headers, deferred, overrideMimeType, timeout); -======= - var xhr = Resource._Implementations.loadWithXhr(resource.url, responseType, method, data, headers, deferred, overrideMimeType, request); ->>>>>>> Stashed changes + var xhr = Resource._Implementations.loadWithXhr(resource.url, responseType, method, data, headers, deferred, overrideMimeType, timeout, request); if (defined(xhr) && defined(xhr.abort)) { request.cancelFunction = function() { xhr.abort(); + request.cancel(); }; } return deferred.promise; @@ -1897,11 +1894,7 @@ define([ }).end(); } -<<<<<<< Updated upstream - Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType, timeout) { -======= - Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType, request) { ->>>>>>> Stashed changes + Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType, timeout, request) { var dataUriRegexResult = dataUriRegex.exec(url); if (dataUriRegexResult !== null) { deferred.resolve(decodeDataUri(dataUriRegexResult, responseType)); @@ -1992,7 +1985,7 @@ define([ var newXHR; setTimeout(function(){ if (!request.cancelled){ - newXHR = loadWithXhr.load.call(this,newURL, responseType, method, data, headers, deferred, overrideMimeType, timeout, request); + newXHR = Resource._Implementations.loadWithXhr.call(this,newURL, responseType, method, data, headers, deferred, overrideMimeType, timeout, request); } else { //user cancel request after waking from sleep return; From 969cb21d1ef2b835b4b7b2a24f5c8cbbffddef95 Mon Sep 17 00:00:00 2001 From: Jason-DNetto Date: Tue, 24 Jul 2018 08:29:54 +1000 Subject: [PATCH 3/3] Update CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 5ca13311e4ac..d8fdf7e5175e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ Change Log * Fixed a bug that could cause tiles to be missing from the globe surface, especially when starting with the camera zoomed close to the surface. * Added support for refreshing expired tokens for `ArcGisMapServerImageryProvider` via callback registered with `options.requestNewToken` in constructor. * Added support for `parameters` to `ArcGisMapServerImageryProvider`. +* Added Support for HTTP 202 headers, and cancelling them if the request object is marked as cancelled. ### 1.46 - 2018-06-01