Skip to content

Commit 41e53d9

Browse files
committed
fix($http): fix response headers with an empty value
Empty response header values are legal (http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html). Return an empty string instead of null, which is returned when the header does not exist. Closes angular#7779
1 parent a9352c1 commit 41e53d9

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/ng/http.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ function headersGetter(headers) {
6363
if (!headersObj) headersObj = parseHeaders(headers);
6464

6565
if (name) {
66-
return headersObj[lowercase(name)] || null;
66+
name = lowercase(name);
67+
return headersObj.hasOwnProperty(name) ? headersObj[name] : null;
6768
}
6869

6970
return headersObj;

test/ng/httpSpec.js

+9
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,15 @@ describe('$http', function() {
816816
});
817817

818818

819+
it('should handle empty response header', function() {
820+
$httpBackend.expect('GET', '/url', undefined)
821+
.respond(200, '', { 'Custom-Empty-Response-Header': '' });
822+
$http.get('/url').success(callback);
823+
$httpBackend.flush();
824+
expect(callback).toHaveBeenCalledOnce();
825+
expect(callback.mostRecentCall.args[2]('custom-empty-response-Header')).toBe('');
826+
});
827+
819828
it('should have delete()', function() {
820829
$httpBackend.expect('DELETE', '/url').respond('');
821830
$http['delete']('/url');

0 commit comments

Comments
 (0)