esri-leaflet icon indicating copy to clipboard operation
esri-leaflet copied to clipboard

Provide DynamicLayer with fetch options extension

Open syntax-punk opened this issue 2 years ago • 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.

syntax-punk avatar Dec 07 '21 12:12 syntax-punk

@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

jwasilgeo avatar Dec 08 '21 20:12 jwasilgeo

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?

syntax-punk avatar Dec 09 '21 09:12 syntax-punk

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 https://github.com/Esri/esri-leaflet/issues/1303#issuecomment-989151996. 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.

jwasilgeo avatar Dec 09 '21 15:12 jwasilgeo