This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -771,7 +771,7 @@ function $HttpProvider() {
771771 function transformResponse ( response ) {
772772 // make a copy since the response must be cacheable
773773 var resp = extend ( { } , response ) ;
774- if ( config . method === 'HEAD' ) {
774+ if ( ! response . data ) {
775775 resp . data = response . data ;
776776 } else {
777777 resp . data = transformData ( response . data , response . headers , config . transformResponse ) ;
Original file line number Diff line number Diff line change @@ -1116,6 +1116,16 @@ describe('$http', function() {
11161116 expect ( callback . mostRecentCall . args [ 0 ] ) . toEqual ( '' ) ;
11171117 } ) ;
11181118
1119+ it ( 'should not attempt to deserialize json for an empty response whose header contains application/json' , function ( ) {
1120+ //per http spec for Content-Type, HEAD request should return a Content-Type header
1121+ //set to what the content type would have been if a get was sent
1122+ $httpBackend . expect ( 'GET' , '/url' ) . respond ( '' , { 'Content-Type' : 'application/json' } ) ;
1123+ $http ( { method : 'GET' , url : '/url' } ) . success ( callback ) ;
1124+ $httpBackend . flush ( ) ;
1125+
1126+ expect ( callback ) . toHaveBeenCalledOnce ( ) ;
1127+ expect ( callback . mostRecentCall . args [ 0 ] ) . toEqual ( '' ) ;
1128+ } ) ;
11191129
11201130 it ( 'should not deserialize tpl beginning with ng expression' , function ( ) {
11211131 $httpBackend . expect ( 'GET' , '/url' ) . respond ( '{{some}}' ) ;
You can’t perform that action at this time.
0 commit comments