mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
fix($httpBackend): use ActiveX XHR when making PATCH requests on IE8
IE8's native XHR doesn't support PATCH requests, but the ActiveX one does. I'm also removing the noxhr error doc because nobody will ever get that error. Closes #2518 Closes #5043
This commit is contained in:
parent
6a6f71f238
commit
6c17d02bc4
4 changed files with 21 additions and 24 deletions
|
|
@ -1,9 +0,0 @@
|
|||
@ngdoc error
|
||||
@name $httpBackend:noxhr
|
||||
@fullName Unsupported XHR
|
||||
@description
|
||||
|
||||
This error occurs in browsers that do not support XmlHttpRequest. AngularJS
|
||||
supports Safari, Chrome, Firefox, Opera, IE8 and higher, and mobile browsers
|
||||
(Android, Chrome Mobile, iOS Safari). To avoid this error, use an officially
|
||||
supported browser.
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
'use strict';
|
||||
|
||||
var XHR = window.XMLHttpRequest || function() {
|
||||
function createXhr(method) {
|
||||
// IE8 doesn't support PATCH method, but the ActiveX object does
|
||||
/* global ActiveXObject */
|
||||
try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e1) {}
|
||||
try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (e2) {}
|
||||
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e3) {}
|
||||
throw minErr('$httpBackend')('noxhr', "This browser does not support XMLHttpRequest.");
|
||||
};
|
||||
return (msie <= 8 && lowercase(method) === 'patch')
|
||||
? new ActiveXObject('Microsoft.XMLHTTP')
|
||||
: new window.XMLHttpRequest();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -28,11 +28,11 @@ var XHR = window.XMLHttpRequest || function() {
|
|||
*/
|
||||
function $HttpBackendProvider() {
|
||||
this.$get = ['$browser', '$window', '$document', function($browser, $window, $document) {
|
||||
return createHttpBackend($browser, XHR, $browser.defer, $window.angular.callbacks, $document[0]);
|
||||
return createHttpBackend($browser, createXhr, $browser.defer, $window.angular.callbacks, $document[0]);
|
||||
}];
|
||||
}
|
||||
|
||||
function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument) {
|
||||
function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDocument) {
|
||||
var ABORTED = -1;
|
||||
|
||||
// TODO(vojta): fix the signature
|
||||
|
|
@ -57,7 +57,9 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument)
|
|||
delete callbacks[callbackId];
|
||||
});
|
||||
} else {
|
||||
var xhr = new XHR();
|
||||
|
||||
var xhr = createXhr(method);
|
||||
|
||||
xhr.open(method, url, true);
|
||||
forEach(headers, function(value, key) {
|
||||
if (isDefined(value)) {
|
||||
|
|
|
|||
4
src/ngMock/angular-mocks.js
vendored
4
src/ngMock/angular-mocks.js
vendored
|
|
@ -1572,6 +1572,10 @@ function MockHttpExpectation(method, url, data, headers) {
|
|||
};
|
||||
}
|
||||
|
||||
function createMockXhr() {
|
||||
return new MockXhr();
|
||||
}
|
||||
|
||||
function MockXhr() {
|
||||
|
||||
// hack for testing $http, $httpBackend
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ describe('$httpBackend', function() {
|
|||
})
|
||||
}
|
||||
};
|
||||
$backend = createHttpBackend($browser, MockXhr, fakeTimeout, callbacks, fakeDocument);
|
||||
$backend = createHttpBackend($browser, createMockXhr, fakeTimeout, callbacks, fakeDocument);
|
||||
callback = jasmine.createSpy('done');
|
||||
}));
|
||||
|
||||
|
|
@ -250,7 +250,7 @@ describe('$httpBackend', function() {
|
|||
expect(response).toBe('response');
|
||||
});
|
||||
|
||||
$backend = createHttpBackend($browser, SyncXhr);
|
||||
$backend = createHttpBackend($browser, function() { return new SyncXhr() });
|
||||
$backend('GET', '/url', null, callback);
|
||||
expect(callback).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
|
@ -426,7 +426,7 @@ describe('$httpBackend', function() {
|
|||
|
||||
|
||||
it('should convert 0 to 200 if content', function() {
|
||||
$backend = createHttpBackend($browser, MockXhr);
|
||||
$backend = createHttpBackend($browser, createMockXhr);
|
||||
|
||||
$backend('GET', 'file:///whatever/index.html', null, callback);
|
||||
respond(0, 'SOME CONTENT');
|
||||
|
|
@ -437,7 +437,7 @@ describe('$httpBackend', function() {
|
|||
|
||||
|
||||
it('should convert 0 to 404 if no content', function() {
|
||||
$backend = createHttpBackend($browser, MockXhr);
|
||||
$backend = createHttpBackend($browser, createMockXhr);
|
||||
|
||||
$backend('GET', 'file:///whatever/index.html', null, callback);
|
||||
respond(0, '');
|
||||
|
|
@ -465,7 +465,7 @@ describe('$httpBackend', function() {
|
|||
|
||||
try {
|
||||
|
||||
$backend = createHttpBackend($browser, MockXhr);
|
||||
$backend = createHttpBackend($browser, createMockXhr);
|
||||
|
||||
$backend('GET', '/whatever/index.html', null, callback);
|
||||
respond(0, '');
|
||||
|
|
@ -480,7 +480,7 @@ describe('$httpBackend', function() {
|
|||
|
||||
|
||||
it('should return original backend status code if different from 0', function () {
|
||||
$backend = createHttpBackend($browser, MockXhr);
|
||||
$backend = createHttpBackend($browser, createMockXhr);
|
||||
|
||||
// request to http://
|
||||
$backend('POST', 'http://rest_api/create_whatever', null, callback);
|
||||
|
|
|
|||
Loading…
Reference in a new issue