jashkenas/backbone — pull request #2748 by HashanP (2013-09-08 07:34:46+00:00)
Title: Added simple custom header support

Super sorry about "Mahor". No idea how that pull request was actually sent. Probably, because I was drunk. I did actually write a proper pull request but then realised my beforeSend() error, and cancelled for I decided it was not the best time to code. But before I logged out I did realise that a pull request had been sent and cancelled. Anyway, the reason I wanted this pull request was because I wanted a more elegant, much more elegant way of custom headers that are automatically added to each and every request, especially useful for CSRF tokens. But you probably got the gist of the code already. Here's an example:

``Backbone.headers["X-CSRF-Token"] = $('#token').val()``

In addition, I've added to the docs.