Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Martinsos opened this issue Jan 21, 2015 · 19 comments
Open

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

Martinsos opened this issue Jan 21, 2015 · 19 comments
Milestone

Comments

@Martinsos
Copy link

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!

@TheSharpieOne
Copy link
Contributor

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 TheSharpieOne self-assigned this Feb 9, 2015
@TheSharpieOne TheSharpieOne added this to the 2.0.0 milestone Feb 12, 2015
@psi-4ward
Copy link
Contributor

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.

@TheSharpieOne
Copy link
Contributor

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

@crmn111
Copy link

crmn111 commented Feb 24, 2015

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

@TheSharpieOne
Copy link
Contributor

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.

@psi-4ward
Copy link
Contributor

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.

@ocorsvall
Copy link

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

@snowcxt
Copy link

snowcxt commented May 21, 2015

+1

1 similar comment
@tommykennedy
Copy link

+1

@TheSharpieOne
Copy link
Contributor

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
Copy link
Contributor

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.

@AdamJessop
Copy link

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.

@snowcxt
Copy link

snowcxt commented May 28, 2015

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

@TheSharpieOne
Copy link
Contributor

@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.

@snowcxt
Copy link

snowcxt commented May 28, 2015

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

@TheSharpieOne
Copy link
Contributor

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
Copy link
Contributor

@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.

@jojo897
Copy link

jojo897 commented Nov 6, 2016

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

@ciriac
Copy link

ciriac commented Nov 16, 2016

Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants