pouchdb/pouchdb — pull request #2455 by dereke (2014-07-09 09:41:04+00:00)
Title: Add a beforeSend hook to ajax settings

# Add a beforeSend hook to ajax settings
This confirms to the "standard" set by jQuery/zepto when performing ajax requests, the beforeSend method executes just before the request it is sent to the server.

In jQuery/zepto you can cancel the request by returning false in this method. I've not implemented this as I am not sure it is safe during an operation like replication, or actually if it is ever useful.

# Usage
```
new PouchDB(dbs.name, {
ajax: {
beforeSend: function(xhr, options){
}
}
});
```

# Reason for change:

To manipulate the request when using alternative authentication methods such as OAuth

# OAuth example

```
var OAuth = require('oauth-1.0a')

var oauth = OAuth({
consumer: {
public: 'consumerKey1'
secret: 'key1Secret'
}
});

var token = {
public: 'token1'
secret: 'token1Secret'
};

new PouchDB(dbs.name, {
ajax: {
beforeSend: function(xhr, options){
authHeaders = oauth.toHeader(oauth.authorize(options, token));
xhr.setRequestHeader('Authorization', authHeaders.Authorization);
}
}
});
```