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

Commit 6c17d02

Browse files
committed
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
1 parent 6a6f71f commit 6c17d02

File tree

4 files changed

+21
-24
lines changed

4 files changed

+21
-24
lines changed

Diff for: docs/content/error/httpBackend/noxhr.ngdoc

-9
This file was deleted.

Diff for: src/ng/httpBackend.js

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

3-
var XHR = window.XMLHttpRequest || function() {
3+
function createXhr(method) {
4+
// IE8 doesn't support PATCH method, but the ActiveX object does
45
/* global ActiveXObject */
5-
try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e1) {}
6-
try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (e2) {}
7-
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e3) {}
8-
throw minErr('$httpBackend')('noxhr', "This browser does not support XMLHttpRequest.");
9-
};
6+
return (msie <= 8 && lowercase(method) === 'patch')
7+
? new ActiveXObject('Microsoft.XMLHTTP')
8+
: new window.XMLHttpRequest();
9+
}
1010

1111

1212
/**
@@ -28,11 +28,11 @@ var XHR = window.XMLHttpRequest || function() {
2828
*/
2929
function $HttpBackendProvider() {
3030
this.$get = ['$browser', '$window', '$document', function($browser, $window, $document) {
31-
return createHttpBackend($browser, XHR, $browser.defer, $window.angular.callbacks, $document[0]);
31+
return createHttpBackend($browser, createXhr, $browser.defer, $window.angular.callbacks, $document[0]);
3232
}];
3333
}
3434

35-
function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument) {
35+
function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDocument) {
3636
var ABORTED = -1;
3737

3838
// TODO(vojta): fix the signature
@@ -57,7 +57,9 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument)
5757
delete callbacks[callbackId];
5858
});
5959
} else {
60-
var xhr = new XHR();
60+
61+
var xhr = createXhr(method);
62+
6163
xhr.open(method, url, true);
6264
forEach(headers, function(value, key) {
6365
if (isDefined(value)) {

Diff for: src/ngMock/angular-mocks.js

+4
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,10 @@ function MockHttpExpectation(method, url, data, headers) {
15721572
};
15731573
}
15741574

1575+
function createMockXhr() {
1576+
return new MockXhr();
1577+
}
1578+
15751579
function MockXhr() {
15761580

15771581
// hack for testing $http, $httpBackend

Diff for: test/ng/httpBackendSpec.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('$httpBackend', function() {
5353
})
5454
}
5555
};
56-
$backend = createHttpBackend($browser, MockXhr, fakeTimeout, callbacks, fakeDocument);
56+
$backend = createHttpBackend($browser, createMockXhr, fakeTimeout, callbacks, fakeDocument);
5757
callback = jasmine.createSpy('done');
5858
}));
5959

@@ -250,7 +250,7 @@ describe('$httpBackend', function() {
250250
expect(response).toBe('response');
251251
});
252252

253-
$backend = createHttpBackend($browser, SyncXhr);
253+
$backend = createHttpBackend($browser, function() { return new SyncXhr() });
254254
$backend('GET', '/url', null, callback);
255255
expect(callback).toHaveBeenCalledOnce();
256256
});
@@ -426,7 +426,7 @@ describe('$httpBackend', function() {
426426

427427

428428
it('should convert 0 to 200 if content', function() {
429-
$backend = createHttpBackend($browser, MockXhr);
429+
$backend = createHttpBackend($browser, createMockXhr);
430430

431431
$backend('GET', 'file:///whatever/index.html', null, callback);
432432
respond(0, 'SOME CONTENT');
@@ -437,7 +437,7 @@ describe('$httpBackend', function() {
437437

438438

439439
it('should convert 0 to 404 if no content', function() {
440-
$backend = createHttpBackend($browser, MockXhr);
440+
$backend = createHttpBackend($browser, createMockXhr);
441441

442442
$backend('GET', 'file:///whatever/index.html', null, callback);
443443
respond(0, '');
@@ -465,7 +465,7 @@ describe('$httpBackend', function() {
465465

466466
try {
467467

468-
$backend = createHttpBackend($browser, MockXhr);
468+
$backend = createHttpBackend($browser, createMockXhr);
469469

470470
$backend('GET', '/whatever/index.html', null, callback);
471471
respond(0, '');
@@ -480,7 +480,7 @@ describe('$httpBackend', function() {
480480

481481

482482
it('should return original backend status code if different from 0', function () {
483-
$backend = createHttpBackend($browser, MockXhr);
483+
$backend = createHttpBackend($browser, createMockXhr);
484484

485485
// request to http://
486486
$backend('POST', 'http://rest_api/create_whatever', null, callback);

0 commit comments

Comments
 (0)