diff --git a/src/ng/http.js b/src/ng/http.js index 4a0a70d1f4a5..bd56aa4837b7 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,8 @@ function headersGetter(headers) { if (!headersObj) headersObj = parseHeaders(headers); if (name) { - return headersObj[lowercase(name)] || null; + name = lowercase(name); + return hasOwnProperty.call(headersObj, name) ? headersObj[name] : null; } 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');