Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OGC API Features ignores "X-Qgis-Service-Url" header #53367

Closed
2 tasks done
JakobMiksch opened this issue Jun 5, 2023 · 3 comments
Closed
2 tasks done

OGC API Features ignores "X-Qgis-Service-Url" header #53367

JakobMiksch opened this issue Jun 5, 2023 · 3 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Server Related to QGIS server

Comments

@JakobMiksch
Copy link

JakobMiksch commented Jun 5, 2023

What is the bug or the crash?

For requests to QGIS server it is possible to set the HEADER X-Qgis-Service-Url (see here). This causes the server to display a different URL of itself in the responses, for example in the capabilities document.

This works well for the traditional OGC standards like WMS and WFS. But it does not work for OGC API Features.

Steps to reproduce the issue

Start a QGIS Server:

Make a request to a project that has WFS/OGC API Features activated:

curl --location 'http://localhost:8380/wfs3/conformance?MAP=/PATH/TO/YOUR/PPROJECT' --header 'X-Qgis-Service-Url: http://www.example.com'

The actual response is:

{
    "conformsTo": [
        "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/core",
        "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/oas30",
        "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/html",
        "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/geojson"
    ],
    "links": [
        {
            "href": "http://localhost:8380/wfs3/conformance.json?MAP=/PATH/TO/YOUR/PPROJECT",  <--
            "rel": "self",
            "title": "WFS 3.0 conformance classes as JSON",
            "type": "application/json"
        },
        {
            "href": "http://localhost:8380/wfs3/conformance.html?MAP=/PATH/TO/YOUR/PPROJECT", <--
            "rel": "alternate",
            "title": "WFS 3.0 conformance classes as HTML",
            "type": "text/html"
        }
    ],
    "timeStamp": "2023-06-05T14:59:57Z"
}

The expected response should be:

{
    "conformsTo": [
        "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/core",
        "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/oas30",
        "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/html",
        "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/geojson"
    ],
    "links": [
        {
            "href": "http://www.example.com/wfs3/conformance.json", <--
            "rel": "self",
            "title": "WFS 3.0 conformance classes as JSON",
            "type": "application/json"
        },
        {
            "href": "http://www.example.com/wfs3/conformance.html", <--
            "rel": "alternate",
            "title": "WFS 3.0 conformance classes as HTML",
            "type": "text/html"
        }
    ],
    "timeStamp": "2023-06-05T14:59:57Z"
}

The links in the document should be replaced by the URL provided in the HEADER X-Qgis-Service-Url

Versions

QGIS Server is started via this docker image: camptocamp/qgis-server:3.28 (link to repo]

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

  • I tried with a new QGIS profile (not possible in this context)

Additional context

No response

@JakobMiksch JakobMiksch added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Jun 5, 2023
@elpaso elpaso added the Server Related to QGIS server label Jun 6, 2023
@elpaso
Copy link
Contributor

elpaso commented Jun 6, 2023

I think this is a won't fix: there is a substantial difference between the old style services (WMS, WFS etc.) and the new REST services (like OAPIF) which is that the base URL path is fixed in the old-style services (while the query string changes) while it changes in the new ones depending on the different endpoints of the collection items.

Besides that your example does not conform the the specifications of the REST API: the base URL should not contain any query string, you should rewrite your path or use another mechanism to build an URL which contains the MAP information in the base path (like the landing page server plugin does).

In any event there are other ways to set the base URL for the OAPIF service in a real life deployment (by using any URL rewrite or proxy headers X-Forwarded-Host in the web server configuration).

@elpaso elpaso closed this as not planned Won't fix, can't repro, duplicate, stale Jun 6, 2023
@JakobMiksch
Copy link
Author

@elpaso thanks for your explanation.

In any event there are other ways to set the base URL for the OAPIF service in a real life deployment (by using any URL rewrite or proxy headers X-Forwarded-Host in the web server configuration).

This is exactly my use case. My QGIS Server itself is not directly exposed to the user. The requests are proxied by a middleware. For WMS and WFS I can add the header X-Qgis-Service-Url via the middleware, so for the user it looks like as the middleware would publish the OGC services.

I would like to accomplish the same with OAPIF. Do you know if this is possible with build-in features from QGIS Server?

@elpaso
Copy link
Contributor

elpaso commented Jun 6, 2023

It may depend on your particular stack, but this works for me:

$ REQUEST_URI='http://test_server.com:8080/wfs3/index.json' QGIS_PROJECT_FILE="$(pwd)/gh_53213.qgs" /usr/lib/cgi-bin/qgis_mapserv.fcgi
Warning 1: Unable to find driver ECW to unload from GDAL_SKIP environment variable.
Warning 1: Unable to find driver ECW to unload from GDAL_SKIP environment variable.
Warning 1: Unable to find driver JP2ECW to unload from GDAL_SKIP environment variable.
"Loading native module /usr/lib/qgis/server/libdummy.so"
"Loading native module /usr/lib/qgis/server/liblandingpage.so"
"Loading native module /usr/lib/qgis/server/libwcs.so"
"Loading native module /usr/lib/qgis/server/libwfs.so"
"Loading native module /usr/lib/qgis/server/libwfs3.so"
"Loading native module /usr/lib/qgis/server/libwms.so"
"Loading native module /usr/lib/qgis/server/libwmts.so"
Content-Length: 688
Content-Type: application/json
Server:  QGIS FCGI server - QGIS version 3.30.3-'s-Hertogenbosch
Status:  200
{"links":[{"href":"http://test_server.com:8080/wfs3.json","rel":"self","title":"Landing page as JSON","type":"application/json"},{"href":"http://test_server.com:8080/wfs3.html","rel":"alternate","title":"Landing page as HTML","type":"text/html"},{"href":"http://test_server.com:8080/wfs3/collections","rel":"data","title":"Feature collections","type":"application/json"},{"href":"http://test_server.com:8080/wfs3/conformance","rel":"conformance","title":"Conformance classes","type":"application/json"},{"href":"http://test_server.com:8080/wfs3/api","rel":"service-desc","title":"API description","type":"application/vnd.oai.openapi+json;version=3.0"}],"timeStamp":"2023-06-06T15:56:53Z"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Server Related to QGIS server
Projects
None yet
Development

No branches or pull requests

2 participants