Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add Content-Type header for PUT and DELETE xhr requests
  • Loading branch information
knapo authored and Di Peng committed Jun 15, 2011
commit 8a23dc41ecb24dc51f542dcda5b19f9ca4ebc59a
3 changes: 2 additions & 1 deletion src/Browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ var XHR_HEADERS = {
"Accept": "application/json, text/plain, */*",
"X-Requested-With": "XMLHttpRequest"
},
POST: {'Content-Type': 'application/x-www-form-urlencoded'}
NON_GET: {'Content-Type': 'application/x-www-form-urlencoded'}
};
XHR_HEADERS.POST = XHR_HEADERS.PUT = XHR_HEADERS.DELETE = XHR_HEADERS.NON_GET

/**
* @private
Expand Down
20 changes: 16 additions & 4 deletions test/BrowserSpecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,23 @@ describe('browser', function(){
expect(xhr.headers['Content-Type']).not.toBeDefined();
});

it('should set Content-type header for POST requests', function() {
browser.xhr('POST', 'URL', 'POST-DATA', function(c, r) {});
describe('non GET requests', function(){
afterEach(function() {
expect(xhr.headers['Content-Type']).toBeDefined();
expect(xhr.headers['Content-Type']).toEqual('application/x-www-form-urlencoded');
});

it('should set Content-type header for POST requests', function() {
browser.xhr('POST', 'URL', 'POST-DATA', function(c, r) {});
});

expect(xhr.headers['Content-Type']).toBeDefined();
expect(xhr.headers['Content-Type']).toEqual('application/x-www-form-urlencoded');
it('should set Content-type header for PUT requests', function() {
browser.xhr('PUT', 'URL', 'POST-DATA', function(c, r) {});
});

it('should set Content-type header for DELETE requests', function() {
browser.xhr('PUT', 'URL', 'POST-DATA', function(c, r) {});
});
});

it('should set default headers for custom methods', function() {
Expand Down