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

Commit 6c17d02

Browse files
committedJan 3, 2014
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
 

‎docs/content/error/httpBackend/noxhr.ngdoc

-9
This file was deleted.

‎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)) {

‎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

‎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);

6 commit comments

Comments
 (6)

cgrodriguez commented on Jan 14, 2014

@cgrodriguez

@IgorMinar I have a very simple routing example that is working on angular 1.2.6 and isn't working on 1.2.7 (just ie8, working on firefox and chrome). Is it possible that this commit is breaking routing in ie8? When I replace this code on 1.2.7 (and 1.2.8) with the previous code on 1.2.6 it works again. Here is a plunkr with the example I was talking about: http://plnkr.co/edit/Tpceyo689yEC8WRHiMG2?p=preview
Also I don't know if this is the right place to submit this, should I open an issue with the problem (I'm not very familiar with github, sorry)?

caitp commented on Jan 14, 2014

@caitp
Contributor

@cgrodriguez that plnkr seems to work fine in ie8

cgrodriguez commented on Jan 14, 2014

@cgrodriguez

Does it? Not for me, I get Typeerrors in ie8 console when clicking on links and views aren't shown. Same thing is happening in other projects I updated angular to 1.2.7 or 1.2.8. When debugging it, createXhr function is throwing the TypeError exception I talked about :(

caitp commented on Jan 14, 2014

@caitp
Contributor

on saucelabs I'm not seeing any problems in the webconsole with the default browser settings. Maybe you have a security policy or something causing the issue?

cgrodriguez commented on Jan 14, 2014

@cgrodriguez

Thought about that and tried a bit without success. I'll give it another try asap and keep you updated. Thanks for your time and help!

cgrodriguez commented on Jan 15, 2014

@cgrodriguez

It was indeed a security issue, I had the "Enable Native xmlHTTP support" disabled so the "new window.XMLHttpRequest()" line threw an exception. I'll see if I can work around this since I can't tweak security settings for users at work. Thanks again! :)

This repository has been archived.