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

Commit f25ca33

Browse files
committed
fix($http): apply transformResponse when data is empty (for non-HEAD requests)
Fixes #12976
1 parent 6b123a0 commit f25ca33

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/ng/http.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ function $HttpProvider() {
999999
function transformResponse(response) {
10001000
// make a copy since the response must be cacheable
10011001
var resp = extend({}, response);
1002-
if (!response.data) {
1002+
if (config.method === 'HEAD') {
10031003
resp.data = response.data;
10041004
} else {
10051005
resp.data = transformData(response.data, response.headers, response.status, config.transformResponse);

test/ng/httpSpec.js

+25
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,31 @@ describe('$http', function() {
13911391
expect(callback).toHaveBeenCalledOnce();
13921392
expect(callback.mostRecentCall.args[0]).toBe('RESP-FIRST:V1');
13931393
});
1394+
1395+
1396+
it('should not apply `transformResponse` on `HEAD` requests', function() {
1397+
var transformResponse = jasmine.createSpy('transformResponse');
1398+
1399+
$httpBackend.expect('HEAD', '/url').respond(200, 'Hello, world !');
1400+
$http.head('/url', {transformResponse: transformResponse});
1401+
$httpBackend.flush();
1402+
1403+
expect(transformResponse).not.toHaveBeenCalled();
1404+
});
1405+
1406+
1407+
it('should apply `transformResponse` on non-`HEAD` requests with empty response',
1408+
function() {
1409+
var transformResponse = jasmine.createSpy('transformResponse');
1410+
1411+
$httpBackend.expect('GET', '/url').respond(200, null);
1412+
$http.get('/url', {transformResponse: transformResponse});
1413+
$httpBackend.flush();
1414+
1415+
expect(transformResponse).toHaveBeenCalledOnce();
1416+
expect(transformResponse.mostRecentCall.args[0]).toBe(null);
1417+
}
1418+
);
13941419
});
13951420
});
13961421

0 commit comments

Comments
 (0)