-
Notifications
You must be signed in to change notification settings - Fork 51
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
Per-request (or scoped) headers #128
Comments
Hello, You can use hooks for that: https://github.com/sindresorhus/ky#hooks this.$http.get('https://example.com', {
hooks: {
beforeRequest: [
(request) => {
request.headers.set('X-Requested-With', 'ky')
}
]
}
}) |
But doesn't this set the headers globally, that is, for the current and also future calls? |
Normally this code will only apply the hooks to the current request |
Ok. Thanks a lot!
El El jue, 5 nov 2020 a las 10:44, Gaetan SENN <notifications@github.com>
escribió:
… Normally this code will only apply the hooks to the current request
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#128 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHNFSUO2EIBG3ZL5YZCOR3SOJ62XANCNFSM4QTL3HSQ>
.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What problem does this feature solve?
As specified in the Migration Guide, under Differences, both setHeaders and setToken are not scoped, which entails that we can only set headers globally, and not as per request. For small apps, this might not be a problem, but it is a problem for bigger ones that include authentication and different types of requests (get, post, put...), because in this cases, each request might need totally different headers.
What do the proposed changes look like?
Give the option to limit the existence of the current globally-defined headers to the next request, and then reset them. Or, enable the possibility to set scoped headers as part of the request options, as in the fetch method.
The text was updated successfully, but these errors were encountered: