Provide DynamicLayer with fetch options extension
syntax-punk opened this issue · 3 comments
Describe the problem
In my current solution a MapService sits behind a proxy api which checks for JWT token provided as an "Authorization" header with each request before forwarding it further to the MapService. I cannot use "token" field of the DynamicLayer here since it simply attaches the token to the url as a query string it doesn't help much.
Describe the proposed solution
I would like to have an ability to either provide "extra" fetch headers to the DynamicLayer or initialize and provide the fetch client which the DynamicLayer can use to make API calls.
@theVoogie have you considered writing your own network request interceptor as a first draft to see if it'll satisfy your use case?
Deeper down the requests coming out esri-leaflet are XMLHttpRequests and internally headers are set in these spots depending on the request type:
https://github.com/Esri/esri-leaflet/blob/master/src/Request.js#L94
https://github.com/Esri/esri-leaflet/blob/master/src/Request.js#L128
Hey @jwasilgeo , I haven't tried it yet and if it's good enough I'm ready to go. Can you suggest any 'good' examples I should follow?
The idea of an interceptor came to my mind from other experience with the ArcGIS API for JavaScript and I believe several other 3rd-party request JS libraries also have such a concept. However, here you'd have to try to experiment and write it by hand, such as in the very first link above #1303 (comment). This was a blog post I found after some quick searching honestly. You may need to try it out globally in your code and see if you can intercept requests to your dynamic map server and add your own logic to apply custom headers.