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

fix($http): return empty headers, ignore properties in Object prototype #10113

Closed
wants to merge 1 commit 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
8 changes: 6 additions & 2 deletions src/ng/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions test/ng/httpSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down