SitePen / dstore

A data infrastructure framework, providing the tools for modelling and interacting with data collections and objects.
http://dstorejs.io/
Other
281 stars 83 forks source link

RequestMemory does not honor HTTP headers #245

Open bosticka opened 3 years ago

bosticka commented 3 years ago

if I do this:

                new RequestMemory({
                    idProperty: 'id',
                    target: target
                    headers: { Authorization: 'Bearer abcd' }
                })

The bearer token for my JWT is not sent with the request and fails against an authenticated API.

I had to make two small changes to get this to work.

In RequestMemory.js:

postscript: function () {
            this.inherited(arguments);
            this.fetch();
        },

changed to:

postscript: function () {
            this.inherited(arguments);
            this.fetch(arguments[0]);
        },

and in Request.js:

        _request: function (kwArgs) {
            kwArgs = kwArgs || {};

            // perform the actual query
            var headers = lang.delegate(this.headers, { Accept: this.accepts });

changed to:

        _request: function (kwArgs) {
            kwArgs = kwArgs || {};

            // perform the actual query
            var headers = lang.mixin(this.headers, { Accept: this.accepts });

The lang.delegate breaks it somehow. It returns a TMP object and the passed in headers do not get mixed in and sent to the server.

Please consider merging these changes.