From 8fba8f19db6fa4e7a5f6c4bd640425738950dc38 Mon Sep 17 00:00:00 2001 From: SchizoDuckie Date: Sat, 22 Aug 2015 02:44:08 +0200 Subject: [PATCH 1/4] Fixes #1678 passing http authentication to XMLHttpRequest by allowing headers.Authorization to be a 2 item username/password array Just to kick things off. todo: docs, tests? --- src/ng/httpBackend.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js index 91fbb7fb7e16..587c822fb4fc 100644 --- a/src/ng/httpBackend.js +++ b/src/ng/httpBackend.js @@ -47,8 +47,14 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc } else { var xhr = createXhr(); + + if (('Authorization' in headers) && headers.Authorization.length == 2) { + xhr.open(method, url, true, headers.Authorization[0], headers.Authorization[1]); + delete headers.Authorization; + } else { + xhr.open(method, url, true); + } - xhr.open(method, url, true); forEach(headers, function(value, key) { if (isDefined(value)) { xhr.setRequestHeader(key, value); From d0ab185cb93947428dc0dd7a3047138978bbde8d Mon Sep 17 00:00:00 2001 From: SchizoDuckie Date: Sat, 22 Aug 2015 12:53:36 +0200 Subject: [PATCH 2/4] defaults for no headers --- src/ng/httpBackend.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js index 587c822fb4fc..a94750481f03 100644 --- a/src/ng/httpBackend.js +++ b/src/ng/httpBackend.js @@ -48,7 +48,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc var xhr = createXhr(); - if (('Authorization' in headers) && headers.Authorization.length == 2) { + if (('Authorization' in headers || {}) && headers.Authorization.length == 2) { xhr.open(method, url, true, headers.Authorization[0], headers.Authorization[1]); delete headers.Authorization; } else { From b1520be56dcc9a3ee9ecc7096e258d9df60c6069 Mon Sep 17 00:00:00 2001 From: SchizoDuckie Date: Sat, 22 Aug 2015 12:57:05 +0200 Subject: [PATCH 3/4] code style --- src/ng/httpBackend.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js index a94750481f03..148304a97817 100644 --- a/src/ng/httpBackend.js +++ b/src/ng/httpBackend.js @@ -48,7 +48,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc var xhr = createXhr(); - if (('Authorization' in headers || {}) && headers.Authorization.length == 2) { + if (isDefined(headers) && isDefined(headers.Authorization) && headers.Authorization.length == 2) { xhr.open(method, url, true, headers.Authorization[0], headers.Authorization[1]); delete headers.Authorization; } else { From 5c6aca3f3ec83d1f6c518840f29e3a67f5a182e8 Mon Sep 17 00:00:00 2001 From: SchizoDuckie Date: Sat, 22 Aug 2015 13:13:16 +0200 Subject: [PATCH 4/4] whitespace --- src/ng/httpBackend.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js index 148304a97817..0b4b405b47d4 100644 --- a/src/ng/httpBackend.js +++ b/src/ng/httpBackend.js @@ -47,7 +47,6 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc } else { var xhr = createXhr(); - if (isDefined(headers) && isDefined(headers.Authorization) && headers.Authorization.length == 2) { xhr.open(method, url, true, headers.Authorization[0], headers.Authorization[1]); delete headers.Authorization;