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

fix($httpBackend): fix HTTP PATCH requests in IE8 #5043

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/ng/httpBackend.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
'use strict';

// We need to be able to detect IE8 so we can use the right AJAX method below
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none of this is needed. just use msie variable that we expose internally

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know. I had assumed it was only exposed in the test environment.

var ie = (function(v, p, needle, undef) {
needle = p.getElementsByTagName('br');
while(
p.innerHTML = '<!--[if gt IE ' + (++v) + ']><br><![endif]-->',
needle[0]
);
return v > 4 ? v : undef;
})(3, document.createElement('p'));

var XHR = window.XMLHttpRequest || function() {
/* 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.");
};
// Fix for IE8's native XMLHttpRequest not supporting PATCH
if (ie === 8) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msie <= 8

XHR = function (method) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XHR is never called with method argument

if (method === 'PATCH') {
return new ActiveXObject('Microsoft.XMLHTTP');
}
return new window.XMLHttpRequest();
};
}


/**
Expand Down
9 changes: 9 additions & 0 deletions test/ng/httpBackendSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ describe('$httpBackend', function() {
expect(xhr.$$data).toBe(null);
});

it('should use ActiveXObject for PATCH on IE8', function () {
xhr = new XHR('PATCH');
if (msie <= 8) {
expect(function() {xhr.toString();}).toThrow();
} else {
expect(xhr.toString()).toMatch(/\[object .+\]/);
}
});

it('should normalize IE\'s 1223 status code into 204', function() {
callback.andCallFake(function(status) {
expect(status).toBe(204);
Expand Down