documentcloud/backbone — pull request #686 by peritus (2011-10-24 15:05:26+00:00)
Title: Backbone.sync: Give options.contentType precedence over hardcoded value

This is a patch for #592, my motivation is similar to the original report there.

I want to `PUT` and `POST` data to my service with a custom Content-Type header (`application/mycompany+json` in this case), by overriding the sync method of the respective model.

```javascript
var MyModel;
MyModel = Backbone.Model.extend({
sync: function(method, model, options) {
return Backbone.sync(method, model, _.extend({
contentType: "application/mycompany+json"
}));
}
});
```

I don't want to copy most of Backbone.sync to my own model to keep things DRY. Not all my models use the same content type, hence using jQuery's global ajaxSetup doesn't work.

Thanks for the great code!

-----

Workaround:

```javascript
var MyModel;
MyModel = Backbone.Model.extend({
sync: function(method, model, options) {
return Backbone.sync(method, model, _.extend({
headers: {
"Content-Type": "application/mycompany+json"
}
}));
}
});
```