Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit b07b53b

Browse files
committed
feat($http): add XHR events configuration option
Allows for arbitrary event handling on requests.
1 parent 8bf5654 commit b07b53b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/ng/http.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ function $HttpProvider() {
11551155
}
11561156

11571157
$httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout,
1158-
config.withCredentials, config.responseType);
1158+
config.withCredentials, config.responseType, config.events);
11591159
}
11601160

11611161
return promise;

src/ng/httpBackend.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function $HttpBackendProvider() {
2828

2929
function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDocument) {
3030
// TODO(vojta): fix the signature
31-
return function(method, url, post, callback, headers, timeout, withCredentials, responseType) {
31+
return function(method, url, post, callback, headers, timeout, withCredentials, responseType, eventHandlers) {
3232
$browser.$$incOutstandingRequestCount();
3333
url = url || $browser.url();
3434

@@ -88,6 +88,20 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
8888
xhr.onerror = requestError;
8989
xhr.onabort = requestError;
9090

91+
if (eventHandlers) {
92+
forEach(eventHandlers, function (value, key) {
93+
if (key !== 'upload') {
94+
xhr.addEventListener(key, value);
95+
}
96+
});
97+
98+
if (eventHandlers.upload) {
99+
forEach(eventHandlers.upload, function (value, key) {
100+
xhr.addEventListener(key, value);
101+
});
102+
}
103+
}
104+
91105
if (withCredentials) {
92106
xhr.withCredentials = true;
93107
}

0 commit comments

Comments
 (0)