aboutsummaryrefslogtreecommitdiffstats
path: root/src/ng
diff options
context:
space:
mode:
Diffstat (limited to 'src/ng')
-rw-r--r--src/ng/http.js5
-rw-r--r--src/ng/httpBackend.js17
2 files changed, 14 insertions, 8 deletions
diff --git a/src/ng/http.js b/src/ng/http.js
index 708a0650..fbdc89a5 100644
--- a/src/ng/http.js
+++ b/src/ng/http.js
@@ -548,7 +548,8 @@ function $HttpProvider() {
* GET request, otherwise if a cache instance built with
* {@link ng.$cacheFactory $cacheFactory}, this cache will be used for
* caching.
- * - **timeout** – `{number}` – timeout in milliseconds.
+ * - **timeout** – `{number|Promise}` – timeout in milliseconds, or {@link ng.$q promise}
+ * that should abort the request when resolved.
* - **withCredentials** - `{boolean}` - whether to to set the `withCredentials` flag on the
* XHR object. See {@link https://developer.mozilla.org/en/http_access_control#section_5
* requests with credentials} for more information.
@@ -927,7 +928,7 @@ function $HttpProvider() {
}
resolvePromise(response, status, headersString);
- $rootScope.$apply();
+ if (!$rootScope.$$phase) $rootScope.$apply();
}
diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js
index 69ac5976..ed8404f9 100644
--- a/src/ng/httpBackend.js
+++ b/src/ng/httpBackend.js
@@ -107,20 +107,25 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument,
}
if (timeout > 0) {
- var timeoutId = $browserDefer(function() {
- status = -1;
- jsonpDone && jsonpDone();
- xhr && xhr.abort();
- }, timeout);
+ var timeoutId = $browserDefer(timeoutRequest, timeout);
+ } else if (timeout && timeout.then) {
+ timeout.then(timeoutRequest);
}
+ function timeoutRequest() {
+ status = -1;
+ jsonpDone && jsonpDone();
+ xhr && xhr.abort();
+ }
+
function completeRequest(callback, status, response, headersString) {
// URL_MATCH is defined in src/service/location.js
var protocol = (url.match(SERVER_MATCH) || ['', locationProtocol])[1];
- // cancel timeout
+ // cancel timeout and subsequent timeout promise resolution
timeoutId && $browserDefer.cancel(timeoutId);
+ jsonpDone = xhr = null;
// fix status code for file protocol (it's always 0)
status = (protocol == 'file') ? (response ? 200 : 404) : status;