From 812c5cb0479e5deebf52befd8c71dc334347bd48 Mon Sep 17 00:00:00 2001 From: Jamshid Afshar Date: Mon, 17 Nov 2014 03:29:22 -0600 Subject: [PATCH] fix($http): return empty headers, ignore properties in Object prototype Fix response headers with an empty value Empty response header values are legal (http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html). The headers getter fn will now only return null if the header property is not an own property. Closes #7779 --- src/ng/http.js | 8 ++++++-- test/ng/httpSpec.js | 11 +++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/ng/http.js b/src/ng/http.js index 4a0a70d1f4a5..57afa3dd70d4 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -26,7 +26,7 @@ function defaultHttpResponseTransform(data, headers) { * @returns {Object} Parsed headers as key value object */ function parseHeaders(headers) { - var parsed = {}, key, val, i; + var parsed = createMap(), key, val, i; if (!headers) return parsed; @@ -63,7 +63,11 @@ function headersGetter(headers) { if (!headersObj) headersObj = parseHeaders(headers); if (name) { - return headersObj[lowercase(name)] || null; + var value = headersObj[lowercase(name)]; + if (value === void 0) { + value = null; + } + return value; } return headersObj; diff --git a/test/ng/httpSpec.js b/test/ng/httpSpec.js index e4e7f86d28bb..3aca14f62ec9 100644 --- a/test/ng/httpSpec.js +++ b/test/ng/httpSpec.js @@ -816,6 +816,17 @@ describe('$http', function() { }); + it('should handle empty response header', function() { + $httpBackend.expect('GET', '/url', undefined) + .respond(200, '', { 'Custom-Empty-Response-Header': '', 'Constructor': '' }); + $http.get('/url').success(callback); + $httpBackend.flush(); + expect(callback).toHaveBeenCalledOnce(); + expect(callback.mostRecentCall.args[2]('custom-empty-response-Header')).toBe(''); + expect(callback.mostRecentCall.args[2]('ToString')).toBe(null); + expect(callback.mostRecentCall.args[2]('Constructor')).toBe(''); + }); + it('should have delete()', function() { $httpBackend.expect('DELETE', '/url').respond(''); $http['delete']('/url');