hapifhir / hapi-fhir

🔥 HAPI FHIR - Java API for HL7 FHIR Clients and Servers
http://hapifhir.io
Apache License 2.0
2.04k stars 1.33k forks source link

Pagination next link broken when SERVER_SERVLET_CONTEXT_PATH is set #5346

Open canon-cmre-craig-matear opened 1 year ago

canon-cmre-craig-matear commented 1 year ago

NOTE: Before filing a ticket, please see the following URL: https://github.com/hapifhir/hapi-fhir/wiki/Getting-Help

Describe the bug We are using the docker image https://github.com/hapifhir/hapi-fhir-jpaserver-starter V6.6.0.

I have set the environment variable SERVER_SERVLET_CONTEXT_PATH to /fhir-service/ so that the rest API is served on http://hapi-jpa.uhsa-data.svc.cluster.local/fhir-service/fhir/

I think this configuration breaks the in the paginated search results.

To Reproduce Steps to reproduce the behavior:

  1. Configure SERVER_SERVLET_CONTEXT_PATH env var in docker image as above
  2. Do a search that will result in pagination e.g http://hapi-jpa.uhsa-data.svc.cluster.local/fhir-service/fhir/Observation
  3. The "next" link in the returned search result will be: http://hapi-jpa.uhsa-data.svc.cluster.local/fhir-service/fhir?_getpages=0ac11e98-307e-4874-80e5-234dd9741cff&_getpagesoffset=200&_count=200&_pretty=true&_bundletype=searchset
  4. If we following the above link the "next" link in that result from that will be: http://hapi-jpa.uhsa-data.svc.cluster.local/fhir?_getpages=0ac11e98-307e-4874-80e5-234dd9741cff&_getpagesoffset=200&_count=200&_pretty=true

Expected behavior

The link at step 4. is wrong, the "fhir-service" component has been striped.

At step 3. the following next link works correctly http://hapi-jpa.uhsa-data.svc.cluster.local/fhir-service/fhir/?_getpages=0ac11e98-307e-4874-80e5-234dd9741cff&_getpagesoffset=200&_count=200&_pretty=true&_bundletype=searchset

Environment (please complete the following information):

relikd commented 7 months ago

Can confirm this. Pagination worked fine in 6.4.x ... and is still broken in 7.0.2

relikd commented 3 months ago

Any news on this? It is still an issue in 7.2 even without setting SERVER_SERVLET_CONTEXT_PATH. It seems the pagination uses whatever is stored as server url. This may be localhost (docker or whatever). However the URL retured to the user should use the same base URL as the request. For example, if you want to access the same server from two different urls, the pagination should return the same url of the origin call. Other use cases are dev environments, e.g., Vite with a proxy url rewrite rule. It even fails if the proxy matches "127.0.0.1" but the Hapi Fhir server returns "localhost".