nathanboktae / q-xhr

XMLHttpRequest using powerful Q promises

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to handle two different "q-xhr" (don't share custom headers)

ibc opened this issue · comments

I use both q and q-xhr as follows:

var Qfactory = require('q');
var Qxhr = require('q-xhr');

var Q1 = Qxhr(XMLHttpRequest, Qfactory);
var Q2 = Qxhr(XMLHttpRequest, Qfactory);

The problem is that I cannot handle both Q1 and Q2 independently. If for example I set:

Q1.xhr.defaults.headers.common.authToken = 'xxxxxxx';

and later I create Q2, then the "authToken" header is overriden (set to null) and Q1 is no longer valid for my needs.

Is there any way to create isolated "instances" of "q-xhr"?

It seems that sending config for each request is the way to go.

Yes, or have one default transformRequest that can know how to set the authToken depending on the context.