camptocamp / ogc-client

A TypeScript library for interacting with geospatial services
https://camptocamp.github.io/ogc-client/
BSD 3-Clause "New" or "Revised" License
66 stars 12 forks source link

Allow adding custom headers #11

Closed JakobMiksch closed 11 months ago

JakobMiksch commented 1 year ago

For some OGC services I need to add a custom header for authorization. However, currently it does not seem possible with this library to add a custom header. I guess a change needs to be done here: https://github.com/camptocamp/ogc-client/blob/main/src/shared/http-utils.ts

I can try to provide a fix. If you have any hint or preference how to implement it, please let me know.

jahow commented 1 year ago

Very good point. To me the following optional parameters would be relevant:

Taken from https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters

These parameters should be provided when creating endpoints and propagated everywhere http requests are done, including in the worker.

JakobMiksch commented 1 year ago

I found out that OpenLayers has a WMS parser as well that is enough for my purposes: https://openlayers.org/en/latest/examples/wms-capabilities.html There I can provide custom headers. That's why, for the moment, I will not use ogc-client for this task anymore. Hence, I also do not plan to make a PR anymore. Sorry for the confusion. Thanks anyway for the great library 🎖️

jahow commented 1 year ago

Thanks, leaving this open because this is still relevant!

JakobMiksch commented 1 year ago

@jahow another option to implement this, would be to allow to hand over custom fetch instances. (see https://rapidapi.com/guides/interceptors-fetch ) It might be easier to implement, because all HTTP stuff can be configured in fetch, whereas this library just does stuff within the OGC API world ...

jahow commented 1 year ago

Hmm, interesting. Maybe instead of having to provide a full fetch instance we could offer a pre-process and post-process hook. The issue I see is that this will not be possible in the worker, so using these hooks would need to disable worker usage altogether.

So I guess at first it would be reasonable to take in an options object for each layer, as this is at least serializable.

JakobMiksch commented 1 year ago

@jahow your suggestion sounds good as well.