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

Per-request (or scoped) headers #128

Closed
kinxos opened this issue Sep 2, 2020 · 4 comments
Closed

Per-request (or scoped) headers #128

kinxos opened this issue Sep 2, 2020 · 4 comments

Comments

@kinxos
Copy link

kinxos commented Sep 2, 2020

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.

Captura de pantalla 2020-09-02 a las 18 10 12

@gaetansenn
Copy link

gaetansenn commented Nov 5, 2020

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')
      }
    ]
  }
})

@atinux atinux closed this as completed Nov 5, 2020
@kinxos
Copy link
Author

kinxos commented Nov 5, 2020

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?

@gaetansenn
Copy link

Normally this code will only apply the hooks to the current request

@kinxos
Copy link
Author

kinxos commented Nov 5, 2020 via email

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

No branches or pull requests

3 participants