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

Feature: Passing custom headers #21

Closed
paolodina opened this issue May 8, 2021 · 5 comments
Closed

Feature: Passing custom headers #21

paolodina opened this issue May 8, 2021 · 5 comments
Assignees
Labels
enhancement New feature or request
Projects

Comments

@paolodina
Copy link
Contributor

paolodina commented May 8, 2021

Hello, I noted that the polyfill allows to pass custom headers.

const es = new EventSourcePolyfill('/events', {
  headers: {
    'X-Custom-Header': 'value'
  }
});

Is this feature supported by vue-sse?

I tried registering VueSSE as follows but with no results:

Vue.use(VueSSE, {
  format: "json",
  polyfill: true,
  url: `${process.env.SERVER_API}/events/`,
  withCredentials: true,
  headers: {
    "X-Custom-Header": "value",
  },
})

I'd need to pass an auth token to the server and passing it with something like

url: `${process.env.SERVER_API}/events/?token=123456`

is not an option.

Eventually, could it technically be added as a new feature? In this case, if you don't want to implement it and maybe with some help, I could try.

@tserkov
Copy link
Owner

tserkov commented May 21, 2021

I could definitely include a polyfillOptions: { ... } option that gets passed directly to the polyfill's constructor quite easily.

The problem is that it would only apply when { polyfill: true } is set, and the browser's native EventSource does not exist. It would require a { forcePolyfill: true } option to tell me to forcibly set the browser's native EventSource to the polyfill (to not break backwards compatibility, since the polyfill only gets set when there is no native).

So a minimal configuration for this to work reliably would look like this:

Vue.use(VueSSE, {
  polyfill: true,
  polyfillOptions: { /* ... */ },
  forcePolyfill: true,
});

If that sounds reasonable, then it shouldn't be a hard addition.

@tserkov tserkov added the enhancement New feature or request label May 21, 2021
@tserkov tserkov changed the title Passing custom headers Feature: Passing custom headers May 21, 2021
@tserkov tserkov self-assigned this May 21, 2021
@tserkov tserkov added this to To do in v2 via automation May 21, 2021
@icheered
Copy link

Is this feature still in development? Would love to have it!

@paolodina
Copy link
Contributor Author

paolodina commented Jul 28, 2021

@icheered Hi!

A combination of lack of skills and time caused that I didn't even started working on it. Bad... I forked this repo and somewhat integrated the feature, but definitely it doesn't worth a share.

I'd like to put a highlight on your now closed ticket as relevant #24.

@tserkov tserkov moved this from To do to In progress in v2 Aug 19, 2021
@tserkov tserkov moved this from In progress to Done in v2 Aug 19, 2021
@tserkov tserkov closed this as completed Aug 19, 2021
@tserkov
Copy link
Owner

tserkov commented Aug 19, 2021

Released in v2.3.0!

Sorry for the delay, I recently moved countries. :)

@icheered
Copy link

Awesome @tserkov, Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
v2
Done
Development

No branches or pull requests

3 participants