From 9c83876f84b7586a9b56bd738dd44cc525239ab3 Mon Sep 17 00:00:00 2001 From: Prajwal K Manjunath Date: Tue, 21 May 2013 12:15:34 +0530 Subject: [PATCH 1/2] experimental xhr event support --- src/ng/http.js | 2 +- src/ng/httpBackend.js | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ng/http.js b/src/ng/http.js index fbdc89a50cf0..1f77546ca428 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -905,7 +905,7 @@ function $HttpProvider() { // if we won't have the response in cache, send the request to the backend if (!cachedResp) { $httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout, - config.withCredentials, config.responseType); + config.withCredentials, config.responseType, config.hooks); } return promise; diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js index ed8404f96cfb..2cfbb3fdcbf3 100644 --- a/src/ng/httpBackend.js +++ b/src/ng/httpBackend.js @@ -32,7 +32,7 @@ function $HttpBackendProvider() { function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument, locationProtocol) { // TODO(vojta): fix the signature - return function(method, url, post, callback, headers, timeout, withCredentials, responseType) { + return function(method, url, post, callback, headers, timeout, withCredentials, responseType, hooks) { var status; $browser.$$incOutstandingRequestCount(); url = url || $browser.url(); @@ -59,9 +59,16 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument, if (value) xhr.setRequestHeader(key, value); }); + // Add listeners for events such as progress + hooks = hooks || {}; + forEach(Object.keys(hooks), function(event) { + xhr.addEventListener(event, hooks[event], false); + }); + // In IE6 and 7, this might be called synchronously when xhr.send below is called and the // response is in the cache. the promise api will ensure that to the app code the api is // always async + xhr.onreadystatechange = function() { if (xhr.readyState == 4) { var responseHeaders = xhr.getAllResponseHeaders(); From aa53be547c3d55214a731d68557bf2a802220be2 Mon Sep 17 00:00:00 2001 From: Prajwal K Manjunath Date: Tue, 21 May 2013 12:25:37 +0530 Subject: [PATCH 2/2] upload hooks --- src/ng/httpBackend.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js index 2cfbb3fdcbf3..4ffa76403932 100644 --- a/src/ng/httpBackend.js +++ b/src/ng/httpBackend.js @@ -61,9 +61,14 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument, // Add listeners for events such as progress hooks = hooks || {}; + var uploadHooks = hooks.upload || {}; + delete hooks.upload; forEach(Object.keys(hooks), function(event) { xhr.addEventListener(event, hooks[event], false); }); + forEach(Object.keys(uploadHooks), function(event) { + xhr.upload.addEventListener(event, uploadHooks[event], false); + }); // In IE6 and 7, this might be called synchronously when xhr.send below is called and the // response is in the cache. the promise api will ensure that to the app code the api is