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 (for non-H…
Browse files Browse the repository at this point in the history
…EAD requests)

Fixes #12976
  • Loading branch information
gkalpak committed Sep 30, 2015
1 parent 6b123a0 commit f25ca33
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ function $HttpProvider() {
function transformResponse(response) {
// make a copy since the response must be cacheable
var resp = extend({}, response);
if (!response.data) {
if (config.method === 'HEAD') {
resp.data = response.data;
} else {
resp.data = transformData(response.data, response.headers, response.status, config.transformResponse);
Expand Down
25 changes: 25 additions & 0 deletions test/ng/httpSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,31 @@ describe('$http', function() {
expect(callback).toHaveBeenCalledOnce();
expect(callback.mostRecentCall.args[0]).toBe('RESP-FIRST:V1');
});


it('should not apply `transformResponse` on `HEAD` requests', function() {
var transformResponse = jasmine.createSpy('transformResponse');

$httpBackend.expect('HEAD', '/url').respond(200, 'Hello, world !');
$http.head('/url', {transformResponse: transformResponse});
$httpBackend.flush();

expect(transformResponse).not.toHaveBeenCalled();
});


it('should apply `transformResponse` on non-`HEAD` requests with empty response',
function() {
var transformResponse = jasmine.createSpy('transformResponse');

$httpBackend.expect('GET', '/url').respond(200, null);
$http.get('/url', {transformResponse: transformResponse});
$httpBackend.flush();

expect(transformResponse).toHaveBeenCalledOnce();
expect(transformResponse.mostRecentCall.args[0]).toBe(null);
}
);
});
});

Expand Down

0 comments on commit f25ca33

Please sign in to comment.