angular-sails icon indicating copy to clipboard operation
angular-sails copied to clipboard

New feature: could you add option to set default headers?

Open Martinsos opened this issue 10 years ago • 19 comments

angularSails supports setting of default headers, could angular-sails also support that? Check http://balderdashy.github.io/angularSails/#/api/ngsails.$sailsSocket, under Setting Headers. By the way, awesome library, has nice documentation and everything, I like it much more than angularSails. Thanks!

Martinsos avatar Jan 21 '15 17:01 Martinsos

We are trying to update everything to work with the new sails.io.js abilities while still working for older sails.io.js. Headers is one of the things that is involved with this. Its in the works along with full test suites for more code confidence as its a lot of changes.

TheSharpieOne avatar Jan 25 '15 20:01 TheSharpieOne

See; https://github.com/janpantel/angular-sails/blob/master/src/service/angular-sails.js#L67 You could add a request interceptor which adds your headers.

psi-4ward avatar Feb 24 '15 07:02 psi-4ward

That will not work because angular-sails uses sails.io.js. sails.io.js will just ignore the headers when it makes the actual call. See: https://github.com/balderdashy/sails.io.js/blob/master/sails.io.js#L725

TheSharpieOne avatar Feb 24 '15 15:02 TheSharpieOne

Is token based Authentication currently possible with angular-sails.., it needs the authorization header?

crmn111 avatar Feb 24 '15 17:02 crmn111

headers (and thus setting the auth header) is on the roadmap for 2.0 which is not 100% ready(the build is passing and what is there works, but not feature complete), but close.

TheSharpieOne avatar Feb 24 '15 17:02 TheSharpieOne

Oh rlly? No header support?

Looked into my sails project: Ive a /login and /login/authSocket route with support to authenticate the Socket. So i dont have to send credentials every request.

psi-4ward avatar Feb 25 '15 11:02 psi-4ward

Any update on the progress on this? As I also would like to be able to send a token in the header.

ocorsvall avatar May 03 '15 22:05 ocorsvall

+1

snowcxt avatar May 21 '15 04:05 snowcxt

+1

tommykennedy avatar May 27 '15 20:05 tommykennedy

I was going to mention beta release of 2.0 and say that it has default headers... but it has been a while since I made it and looking at it now I see.... // TODO: default headers :(

But while I'm at it... RFC for what the default default headers should be (if any). Angular's $http has some defaults mostly around Content-Type... not sure if that is relevant with $sails or not.

TheSharpieOne avatar May 28 '15 02:05 TheSharpieOne

So... there is now 2.0 beta 2 release. It has default headers abilities similar to how angular's $http works, just use $sailsProvider instead of $httpProvider (i.e. $sailsProvider.defaults.headers.get = {'my-header': 'some value'}).

Let me know if you have any issues with 2.0 beta.

TheSharpieOne avatar May 28 '15 04:05 TheSharpieOne

I have just tested this with the following from an AuthService:

$sails.defaults.headers.common = {'Authorization' : 'Bearer ' + token}; $sails.defaults.headers.post = {'Authorization' : 'Bearer ' + token};

Checking the socket frames in chrome devtools I can see that the headers appear to be empty.

AdamJessop avatar May 28 '15 22:05 AdamJessop

Is it possible to automatically append the http headers to the socket, which means we just have to replace the $http with $sails?

snowcxt avatar May 28 '15 22:05 snowcxt

@snowcxt not sure what you mean. Something like "use the headers set in $httpProvider.default.headers when making $sails calls? So it would be something like

finalHeadersSent <- $http.default.headers.common <- $http.default.headers[method] <- $sails.default.headers.common <- $sails.default.headers[method] <- request.config.headers

Each one extending the other to add or override the values.

That could be useful when you want to use both $http and $sails together so you don't have to duplicate setting the headers on $httpProvider and $sailsProvider

Although you could just do $sailsProvider.default.headers = $httpProvider.default.headers to make them the same thing.

TheSharpieOne avatar May 28 '15 22:05 TheSharpieOne

Right. And it's nice to have the "headers" parameter in the $sails function as what $http does.

snowcxt avatar May 28 '15 23:05 snowcxt

It is. You can pass headers in the config and they will be merged into the defaults. Current it is set up to do something like: finalHeadersSent <- $sails.default.headers.common <- $sails.default.headers[method] <- request.config.headers

as you can see here and really here

TheSharpieOne avatar May 29 '15 01:05 TheSharpieOne

@AdamJessop It turns out that if I don't actually update the dist files, then no one gets them :( lol.. yeah, I forgot to run gulp to create the dist files that you use. So 2.0.0-beta-2 dist files are actually 1.x... No fear, 2.0.0-beta.3 has the legit dist files now and you should be able to see the headers working! Give it a try.

@snowcxt as far as your request. I would probably put that ability behind a flag, and if I were to do that and have users/devs set the flag, I might as well just recommend doing $sailsProvider.default.headers = $httpProvider.default.headers as it would be the same affect.

TheSharpieOne avatar May 29 '15 03:05 TheSharpieOne

Has this feature been implemented yet ? Doesn't look like it has, but I may be wrong ...

jojo897 avatar Nov 06 '16 16:11 jojo897

Any update on this?

ciriac avatar Nov 16 '16 10:11 ciriac