Unleash/unleash-proxy-client-js

Add the ability to insert custom headers into the request

travis-walsh opened this issue · 1 comments

Need to ability to pass additional custom headers currently the behavior allows for changing the name of the Authorization header, but not to include additional headers.
new UnleashClient({
url: 'http://host/proxy',
clientKey: 'xxxxxxx',
environment: 'default',
customHeaders: {
'AccessId': 'xxxxxxxxxxxxx',
'AccessSecret: 'xxxxxxxxxxxx'
}
});

headers: {
[this.headerName]: this.clientKey,
Accept: 'application/json',
'Content-Type': 'application/json',
'If-None-Match': this.etag,
},

Thanks for raising this! 😄 We don't currently support adding custom headers directly via the configuration option, but there is a workaround for it:

The config accepts a fetch property, where you can override window.fetch with your own implementation. You can use something like the js-fetch-defaults to have a fetch with the right headers pre-populated. Does that work for you? ☺️

And yeah, I know it's a bit more cumbersome than an additionalHeaders config property. I'll raise this internally and see what we can do 🙋🏼

Update: realized, after posting this message, that you've also opened a PR fixing this. Love it! ❤️