Skip to content

Commit 249efc5

Browse files
feat($http): introduce XHR instances factory - WIP
1 parent 093416f commit 249efc5

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/ng/httpBackend.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
'use strict';
22

3-
function createXhr() {
4-
return new window.XMLHttpRequest();
3+
function $xhrFactoryProvider() {
4+
this.$get = function() {
5+
return function createXhr(method, url) {
6+
return new window.XMLHttpRequest();
7+
};
8+
}
59
}
610

711
/**
@@ -21,8 +25,8 @@ function createXhr() {
2125
* $httpBackend} which can be trained with responses.
2226
*/
2327
function $HttpBackendProvider() {
24-
this.$get = ['$browser', '$window', '$document', function($browser, $window, $document) {
25-
return createHttpBackend($browser, createXhr, $browser.defer, $window.angular.callbacks, $document[0]);
28+
this.$get = ['$browser', '$xhrFactory', '$window', '$document', function($browser, $xhrFactory, $window, $document) {
29+
return createHttpBackend($browser, $xhrFactory, $browser.defer, $window.angular.callbacks, $document[0], $xhrFactory);
2630
}];
2731
}
2832

@@ -46,7 +50,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
4650
});
4751
} else {
4852

49-
var xhr = createXhr();
53+
var xhr = createXhr(method, url); //we could add more arguments here, if needed
5054

5155
xhr.open(method, url, true);
5256
forEach(headers, function(value, key) {

0 commit comments

Comments
 (0)