[QGIS-Developer] Sending a Header when using QgsVectorLayer/gdal with http url

Richard Duivenvoorde rdmailings at duif.net
Thu Jul 22 00:34:19 PDT 2021


Hi Devs,

I'm using a geojson url from an external service to retrieve features in 
a plugin.

But this service wants me to set an 'Accept-Encoding' header to be able 
to retrieve GEOjson (instead of json)...

Is there a way to do this using the QgsVectorLayer-constructor?

I've had a quick look into the code and could not find any header 
related stuff.

And gdal itself in the geojson driver is not mentioning any headers:
https://gdal.org/drivers/vector/geojson.html
The wfs driver seems to have some file to be able to 'set headers' using 
a GDAL_HTTP_HEADER_FILE (https://gdal.org/drivers/vector/wfs.html)
but that seems a little overkill.

My last resort off course is to do the request myself using for example 
a QgsBlockingNetworkRequest (setting the headers), and then feed the 
geojson to a QgsVectorLayer.

But given REST-full api's nowadays favour content-negotiation via 
headers over the use of an extension [0] I think gdal/QGIS should maybe 
be able to set headers in the constructor/context?

Regards,

Richard Duivenvoorde

https://www.baeldung.com/spring-mvc-content-negotiation-json-xml


More information about the QGIS-Developer mailing list