diff options
| author | Igor Minar | 2012-02-28 12:11:03 -0800 | 
|---|---|---|
| committer | Igor Minar | 2012-03-20 11:07:38 -0700 | 
| commit | 1a5bebd927ecd22f9c34617642fdf58fe3f62efb (patch) | |
| tree | 5c0dc039afaf3c476389d20242075ae164bb023e /test | |
| parent | 83155e8fbeebca3a7bc1804cccead7c72581ba47 (diff) | |
| download | angular.js-1a5bebd927ecd22f9c34617642fdf58fe3f62efb.tar.bz2 | |
fix($http): don't send Content-Type header when no data
When a http request has no data (body), we should not send the
Content-Type header as it causes problems for some server-side
frameworks.
Closes #749
Diffstat (limited to 'test')
| -rw-r--r-- | test/service/httpSpec.js | 25 | 
1 files changed, 17 insertions, 8 deletions
diff --git a/test/service/httpSpec.js b/test/service/httpSpec.js index 4c8471d8..43dbf3af 100644 --- a/test/service/httpSpec.js +++ b/test/service/httpSpec.js @@ -340,12 +340,11 @@ describe('$http', function() {        it('should send custom headers', function() {          $httpBackend.expect('GET', '/url', undefined, function(headers) { -          return headers['Custom'] == 'header' && headers['Content-Type'] == 'application/json'; +          return headers['Custom'] == 'header';          }).respond('');          $http({url: '/url', method: 'GET', headers: {            'Custom': 'header', -          'Content-Type': 'application/json'          }});          $httpBackend.flush(); @@ -364,25 +363,25 @@ describe('$http', function() {        it('should set default headers for POST request', function() { -        $httpBackend.expect('POST', '/url', undefined, function(headers) { +        $httpBackend.expect('POST', '/url', 'messageBody', function(headers) {            return headers['Accept'] == 'application/json, text/plain, */*' &&                   headers['X-Requested-With'] == 'XMLHttpRequest' &&                   headers['Content-Type'] == 'application/json';          }).respond(''); -        $http({url: '/url', method: 'POST', headers: {}}); +        $http({url: '/url', method: 'POST', headers: {}, data: 'messageBody'});          $httpBackend.flush();        });        it('should set default headers for PUT request', function() { -        $httpBackend.expect('PUT', '/url', undefined, function(headers) { +        $httpBackend.expect('PUT', '/url', 'messageBody', function(headers) {            return headers['Accept'] == 'application/json, text/plain, */*' &&                   headers['X-Requested-With'] == 'XMLHttpRequest' &&                   headers['Content-Type'] == 'application/json';          }).respond(''); -        $http({url: '/url', method: 'PUT', headers: {}}); +        $http({url: '/url', method: 'PUT', headers: {}, data: 'messageBody'});          $httpBackend.flush();        }); @@ -399,13 +398,13 @@ describe('$http', function() {        it('should override default headers with custom', function() { -        $httpBackend.expect('POST', '/url', undefined, function(headers) { +        $httpBackend.expect('POST', '/url', 'messageBody', function(headers) {            return headers['Accept'] == 'Rewritten' &&                   headers['X-Requested-With'] == 'XMLHttpRequest' &&                   headers['Content-Type'] == 'Rewritten';          }).respond(''); -        $http({url: '/url', method: 'POST', headers: { +        $http({url: '/url', method: 'POST', data: 'messageBody', headers: {            'Accept': 'Rewritten',            'Content-Type': 'Rewritten'          }}); @@ -413,6 +412,16 @@ describe('$http', function() {        }); +      it('should not send Content-Type header if request data/body is undefined', function() { +        $httpBackend.expect('POST', '/url', undefined, function(headers) { +          return !headers.hasOwnProperty('Content-Type'); +        }).respond(''); + +        $http({url: '/url', method: 'POST'}); +        $httpBackend.flush(); +      }); + +        it('should set the XSRF cookie into a XSRF header', inject(function($browser) {          function checkXSRF(secret) {            return function(headers) {  | 
