aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWill Moore2013-01-18 14:09:19 -0800
committerVojta Jina2013-02-14 16:52:02 -0800
commit0fa8e47fb5d2df5aab820691696f19662669eed0 (patch)
treeaecac888230370706c123b21faf844d7fb96d839
parent8043784fd73a4768f4e904fd4121b21cd1fb49b4 (diff)
downloadangular.js-0fa8e47fb5d2df5aab820691696f19662669eed0.tar.bz2
fix($httpBackend): patch for Firefox bug w/ CORS and response headers
A workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=608735 In FF getAllResponseHeaders() returns null if the request is the result of CORS. Tried to format the code so that when a FF patch is released and gains enough traction it can easily be selected and deleted. Heavily inspired by jQuery's patch for the same bug. This patch falls short of passing through custom headers but covers all of the "simple response headers" in the spec at http://www.w3.org/TR/cors/ This commit should get reverted once Firefox 21 gets out. Closes #1468 Conflicts: src/ng/httpBackend.js
-rw-r--r--src/ng/httpBackend.js26
-rw-r--r--test/ng/httpBackendSpec.js3
2 files changed, 27 insertions, 2 deletions
diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js
index 0a12aa23..775d921c 100644
--- a/src/ng/httpBackend.js
+++ b/src/ng/httpBackend.js
@@ -65,8 +65,30 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument,
// always async
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
- completeRequest(
- callback, status || xhr.status, xhr.responseText, xhr.getAllResponseHeaders());
+ var responseHeaders = xhr.getAllResponseHeaders();
+
+ // TODO(vojta): remove once Firefox 21 gets released.
+ // begin: workaround to overcome Firefox CORS http response headers bug
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=608735
+ // Firefox already patched in nightly. Should land in Firefox 21.
+
+ // CORS "simple response headers" http://www.w3.org/TR/cors/
+ var value,
+ simpleHeaders = ["Cache-Control", "Content-Language", "Content-Type",
+ "Expires", "Last-Modified", "Pragma"];
+ if (!responseHeaders) {
+ responseHeaders = "";
+ forEach(simpleHeaders, function (header) {
+ var value = xhr.getResponseHeader(header);
+ if (value) {
+ responseHeaders += header + ": " + value + "\n";
+ }
+ });
+ }
+ // end of the workaround.
+
+ completeRequest(callback, status || xhr.status, xhr.responseText,
+ responseHeaders);
}
};
diff --git a/test/ng/httpBackendSpec.js b/test/ng/httpBackendSpec.js
index 06b63c3c..563b624c 100644
--- a/test/ng/httpBackendSpec.js
+++ b/test/ng/httpBackendSpec.js
@@ -116,6 +116,9 @@ describe('$httpBackend', function() {
};
this.getAllResponseHeaders = valueFn('');
+ // for temporary Firefox CORS workaround
+ // see https://github.com/angular/angular.js/issues/1468
+ this.getResponseHeader = valueFn('');
}
callback.andCallFake(function(status, response) {