]> git.openstreetmap.org Git - nominatim.git/commitdiff
provide full URL in more field
authorSarah Hoffmann <lonvia@denofr.de>
Sun, 6 Aug 2023 15:20:16 +0000 (17:20 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Sun, 6 Aug 2023 15:50:02 +0000 (17:50 +0200)
This is a regression against the PHP version.

Fixes #3138.

nominatim/api/v1/server_glue.py
nominatim/server/falcon/server.py
nominatim/server/starlette/server.py
test/python/api/fake_adaptor.py

index d83adaae646d51f5ca03750e545d91b6eae68db1..d1bcc1dab0d3050bd5ec2a0cad40f1fbad9f0b58 100644 (file)
@@ -69,6 +69,11 @@ class ASGIAdaptor(abc.ABC):
             body of the response to 'output'.
         """
 
+    @abc.abstractmethod
+    def base_uri(self) -> str:
+        """ Return the URI of the original request.
+        """
+
 
     @abc.abstractmethod
     def config(self) -> Configuration:
@@ -481,7 +486,7 @@ async def search_endpoint(api: napi.NominatimAPIAsync, params: ASGIAdaptor) -> A
                                    (str(r.place_id) for r in results if r.place_id))
         queryparts['format'] = fmt
 
-        moreurl = urlencode(queryparts)
+        moreurl = params.base_uri() + '/search?' + urlencode(queryparts)
     else:
         moreurl = ''
 
index 196c519f014212a6a96fe68244d32dada97256c9..e551e54256f531ddc1e101caa2ada639b09b05e4 100644 (file)
@@ -67,6 +67,9 @@ class ParamWrapper(api_impl.ASGIAdaptor):
         self.response.content_type = self.content_type
 
 
+    def base_uri(self) -> str:
+        return cast (str, self.request.forwarded_prefix)
+
     def config(self) -> Configuration:
         return self._config
 
index f89e52a151dac89cf205ce25964f4483cbd5e272..5567ac9c9b9e9986bafdfd4fdb2855c66e7e220b 100644 (file)
@@ -50,6 +50,19 @@ class ParamWrapper(api_impl.ASGIAdaptor):
         return Response(output, status_code=status, media_type=self.content_type)
 
 
+    def base_uri(self) -> str:
+        scheme = self.request.url.scheme
+        host = self.request.url.hostname
+        port = self.request.url.port
+        root = self.request.scope['root_path']
+        if (scheme == 'http' and port == 80) or (scheme == 'https' and port == 443):
+            port = None
+        if port is not None:
+            return f"{scheme}://{host}:{port}{root}"
+
+        return f"{scheme}://{host}{root}"
+
+
     def config(self) -> Configuration:
         return cast(Configuration, self.request.app.state.API.config)
 
index f04381db2ad2683bf7e8dbe41dd28752617b7051..d886d34e20f89057fdcca2b82e263c6e7e1c65fd 100644 (file)
@@ -47,6 +47,9 @@ class FakeAdaptor(glue.ASGIAdaptor):
         return FakeResponse(status, output, self.content_type)
 
 
+    def base_uri(self) -> str:
+        return 'http://test'
+
     def config(self):
         return self._config