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

fix($http): apply transformResponse when data is empty (for non-HEAD requests) #12979

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