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

Commit

Permalink
fix($http): apply transformResponse when data is empty
Browse files Browse the repository at this point in the history
Fixes #12976
  • Loading branch information
gkalpak committed Oct 6, 2015
1 parent 6b123a0 commit b770f97
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/ng/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -999,11 +999,8 @@ function $HttpProvider() {
function transformResponse(response) {
// make a copy since the response must be cacheable
var resp = extend({}, response);
if (!response.data) {
resp.data = response.data;
} else {
resp.data = transformData(response.data, response.headers, response.status, config.transformResponse);
}
resp.data = transformData(response.data, response.headers, response.status,
config.transformResponse);
return (isSuccess(response.status))
? resp
: $q.reject(resp);
Expand Down
19 changes: 19 additions & 0 deletions test/ng/httpSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,25 @@ describe('$http', function() {
expect(callback).toHaveBeenCalledOnce();
expect(callback.mostRecentCall.args[0]).toBe('RESP-FIRST:V1');
});


it('should apply `transformResponse` even if the response data is empty', function(data) {
var callback = jasmine.createSpy('transformResponse');
var config = {transformResponse: callback};

$httpBackend.expect('GET', '/url1').respond(200, undefined);
$httpBackend.expect('GET', '/url2').respond(200, null);
$httpBackend.expect('GET', '/url3').respond(200, '');
$http.get('/url1', config);
$http.get('/url2', config);
$http.get('/url3', config);
$httpBackend.flush();

expect(callback.callCount).toBe(3);
expect(callback.calls[0].args[0]).toBe(undefined);
expect(callback.calls[1].args[0]).toBe(null);
expect(callback.calls[2].args[0]).toBe('');
});
});
});

Expand Down

0 comments on commit b770f97

Please sign in to comment.