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

fix($http): fix response headers with an empty value #10091

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion src/ng/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ function headersGetter(headers) {
if (!headersObj) headersObj = parseHeaders(headers);

if (name) {
return headersObj[lowercase(name)] || null;
name = lowercase(name);
return headersObj.hasOwnProperty(name) ? headersObj[name] : null;
}

return headersObj;
Expand Down
9 changes: 9 additions & 0 deletions test/ng/httpSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,15 @@ describe('$http', function() {
});


it('should handle empty response header', function() {
$httpBackend.expect('GET', '/url', undefined)
.respond(200, '', { 'Custom-Empty-Response-Header': '' });
$http.get('/url').success(callback);
$httpBackend.flush();
expect(callback).toHaveBeenCalledOnce();
expect(callback.mostRecentCall.args[2]('custom-empty-response-Header')).toBe('');
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this change uses hasOwnProperty, add a test for header values in the object prototype, like ToString or Constructor, too.

it('should have delete()', function() {
$httpBackend.expect('DELETE', '/url').respond('');
$http['delete']('/url');
Expand Down