Adding 'Authorization' field to request's header

I’ve tried to post using:

getHomes: function(){
            var token = this.methods.localstoreout('token').access;
            this.request.post(
                'https://app.mysite.io/api/homes/', {
                    headers: {
                        'Authorization': 'Token '+token
                    },
                },
       ......

This will send data through multipart/form-data, i can’t easily access these fields, as Django Rest Framework makes it difficult without using a middleware for the effect.

In order to customize the request’s header i tried this:

Defining a method:

authHeader: function(){
    this.request.setup({
        beforeSend: function () {
            xhr.setRequestHeader ('Authorization', 'Token '+this.methods.localstoreout('token').access);
        }
    });
}, 

and in another method:

    this.methods.authHeader();
    this.request.post(
        'https://app.cleverway.io/api/homes/', {},
        //success
        function (data, status, xhr) {
            console.log('Homes list: '+ data);
       .......

Firstly, xhr is not defined when i call it, although the app object is already instantiated . Do i need to define it like app.request.setup()?

Secondly, it seems like this setup is permanent, i’d need to remove auth headers everytime i call the authHeader method.

Is there an all in one solution, where beforesend is called within the post method?

Ok, problem solved,

authHeader: function(){
    this.request.setup({
        beforeSend: function (xhr) {
            xhr.setRequestHeader ('Authorization', 'Token '+app.methods.localstoreout('token').access);
        }
    });
}, 

This is the correct way of defining the method and on document init i have this verification:

if(app.methods.isLogged()){
    app.methods.authHeader();
    app.methods.keepAlive();
}else{
    // REMOVE AUTHEADERS HERE
    app.methods.logout();
}

Hope it helps someone in the future as there is not much about the beforesend on the forum.