@@ -340,12 +340,11 @@ describe('$http', function() {
340
340
341
341
it ( 'should send custom headers' , function ( ) {
342
342
$httpBackend . expect ( 'GET' , '/url' , undefined , function ( headers ) {
343
- return headers [ 'Custom' ] == 'header' && headers [ 'Content-Type' ] == 'application/json' ;
343
+ return headers [ 'Custom' ] == 'header' ;
344
344
} ) . respond ( '' ) ;
345
345
346
346
$http ( { url : '/url' , method : 'GET' , headers : {
347
347
'Custom' : 'header' ,
348
- 'Content-Type' : 'application/json'
349
348
} } ) ;
350
349
351
350
$httpBackend . flush ( ) ;
@@ -364,25 +363,25 @@ describe('$http', function() {
364
363
365
364
366
365
it ( 'should set default headers for POST request' , function ( ) {
367
- $httpBackend . expect ( 'POST' , '/url' , undefined , function ( headers ) {
366
+ $httpBackend . expect ( 'POST' , '/url' , 'messageBody' , function ( headers ) {
368
367
return headers [ 'Accept' ] == 'application/json, text/plain, */*' &&
369
368
headers [ 'X-Requested-With' ] == 'XMLHttpRequest' &&
370
369
headers [ 'Content-Type' ] == 'application/json' ;
371
370
} ) . respond ( '' ) ;
372
371
373
- $http ( { url : '/url' , method : 'POST' , headers : { } } ) ;
372
+ $http ( { url : '/url' , method : 'POST' , headers : { } , data : 'messageBody' } ) ;
374
373
$httpBackend . flush ( ) ;
375
374
} ) ;
376
375
377
376
378
377
it ( 'should set default headers for PUT request' , function ( ) {
379
- $httpBackend . expect ( 'PUT' , '/url' , undefined , function ( headers ) {
378
+ $httpBackend . expect ( 'PUT' , '/url' , 'messageBody' , function ( headers ) {
380
379
return headers [ 'Accept' ] == 'application/json, text/plain, */*' &&
381
380
headers [ 'X-Requested-With' ] == 'XMLHttpRequest' &&
382
381
headers [ 'Content-Type' ] == 'application/json' ;
383
382
} ) . respond ( '' ) ;
384
383
385
- $http ( { url : '/url' , method : 'PUT' , headers : { } } ) ;
384
+ $http ( { url : '/url' , method : 'PUT' , headers : { } , data : 'messageBody' } ) ;
386
385
$httpBackend . flush ( ) ;
387
386
} ) ;
388
387
@@ -399,20 +398,30 @@ describe('$http', function() {
399
398
400
399
401
400
it ( 'should override default headers with custom' , function ( ) {
402
- $httpBackend . expect ( 'POST' , '/url' , undefined , function ( headers ) {
401
+ $httpBackend . expect ( 'POST' , '/url' , 'messageBody' , function ( headers ) {
403
402
return headers [ 'Accept' ] == 'Rewritten' &&
404
403
headers [ 'X-Requested-With' ] == 'XMLHttpRequest' &&
405
404
headers [ 'Content-Type' ] == 'Rewritten' ;
406
405
} ) . respond ( '' ) ;
407
406
408
- $http ( { url : '/url' , method : 'POST' , headers : {
407
+ $http ( { url : '/url' , method : 'POST' , data : 'messageBody' , headers : {
409
408
'Accept' : 'Rewritten' ,
410
409
'Content-Type' : 'Rewritten'
411
410
} } ) ;
412
411
$httpBackend . flush ( ) ;
413
412
} ) ;
414
413
415
414
415
+ it ( 'should not send Content-Type header if request data/body is undefined' , function ( ) {
416
+ $httpBackend . expect ( 'POST' , '/url' , undefined , function ( headers ) {
417
+ return ! headers . hasOwnProperty ( 'Content-Type' ) ;
418
+ } ) . respond ( '' ) ;
419
+
420
+ $http ( { url : '/url' , method : 'POST' } ) ;
421
+ $httpBackend . flush ( ) ;
422
+ } ) ;
423
+
424
+
416
425
it ( 'should set the XSRF cookie into a XSRF header' , inject ( function ( $browser ) {
417
426
function checkXSRF ( secret ) {
418
427
return function ( headers ) {
0 commit comments