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

Fix UTF16 encoding parsing. #1

Closed fgravin closed 2 years ago

fgravin commented 2 years ago

Use XMLHttpRequest instead of fetch to perform the xhr requests to prevent from encoding issues. fetch seems only able to handle UTF8 charset, while xhr.responseText seems correctly decoded by default.

The URL https://georchestra.cbnbl.org/geoserver/ows?SERVICE=WMS&request=getcapabilities now works.

@jahow let me know if this solution is ok for you, i'all adapt the tests then.

Another solution could have been to try to guess the encoding of the response, and use ArrayBuffer to decode it accordingly.

jahow commented 2 years ago

So I realized that if we get rid of fetch and use XMLHttpRequest it means we put another obstacle for nodejs compatibility. ogc-client is currently not nodejs compatible, there a few things here and there that produce errors, and it's not tested against regressions, but using XMLHttpRequest means the only way to have node compatibility would be to include a polyfill as well.

I'm looking into this issue in a bit more details