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 #7792

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

if (name) {
return headersObj[lowercase(name)] || null;
name = lowercase(name);
return name in headersObj ? headersObj[name] : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't totally like this form. 'constructor' in {} === true, and some browsers have weird things in Object.prototype which you wouldn't expect (like watch, unwatch in Firefox). These don't frequently hit header names, but they definitely could, so I say use hasOwnProperty.call(headersObj, name) instead.

}

return headersObj;
Expand Down
10 changes: 10 additions & 0 deletions test/ng/httpSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,16 @@ 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('');
});


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