pramsey / pgsql-ogr-fdw

PostgreSQL foreign data wrapper for OGR
MIT License
237 stars 34 forks source link

Use of GDAL_HTTP_HEADER_FILE results in error #207

Closed mapcentia closed 3 years ago

mapcentia commented 3 years ago

I'm using ogr_fdw to wrap a GeoJSON HTTP API and it works perfect. But I would like to set custom headers in the request to the GeoJSON. I'm trying this:

CREATE SERVER myserver FOREIGN DATA WRAPPER ogr_fdw OPTIONS ( datasource 'http://gc2core/api/v2/sql/mydb/?q=select%20*%20from%20test.city_center&srs=4326', format 'GeoJSON', config_options 'GDAL_HTTP_HEADER_FILE=/root/headers' )

But I randomly get two different errors:

ERROR: [3] Cannot read /root/headers ERROR: [1] GDALOpen() called on http://gc2core/api/v2/sql/mydb/?q=select%20*%20from%20test.city_center&srs=4326 recursively

The first one is obvious. The second not so much.

Is this the right approach for setting HTTP headers?

PostgreSQL 11.9, GDAL 2.4.0

pramsey commented 3 years ago

"Randomly"? Anyways, one thing that jumps out at me is /root/headers is usually a place that only root can read, and the database usually runs under the 'postgres' user. Try testing with your file in /tmp or some other globally readable area. The fact that it's trying and failing to read the file is a good sign that your config_options are in fact being read and used, so you've cracked that part of the problem.