diff --git a/README.md b/README.md index 15ec977b..cef8f30e 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ Alternatively, set them directly in the environment from which Prez is run. - **`sparql_endpoint`**: Read-only SPARQL endpoint for Prez. Default is `None`. - **`sparql_username`**: A username for the Prez SPARQL endpoint, if required by the RDF DB. Default is `None`. - **`sparql_password`**: A password for the Prez SPARQL endpoint, if required by the RDF DB. Default is `None`. +- **`enable_sparql_endpoint`**: Whether to enable the SPARQL endpoint. I.e. whether prez exposes the remote repository's SPARQL endpoint (typically a triplestore). Default is `False`. NB the SPARQL endpoint when enabled supports POST requests. Prez itself does not make any updates to the remote repository (e.g. the remote Triplestore), however, if the remote SPARQL endpoint is enabled it is then possible that users can make updates to the remote repository using the SPARQL endpoint. #### Network Configuration @@ -193,10 +194,6 @@ Used in conjunction with the Pyoxigraph repo. Specifies a directory (from the re - **`listing_count_limit`**: The maximum number of items to count for a listing endpoint. Counts greater than this limit will be returned as ">N" where N is the limit. Default is `100`. - **`search_count_limit`**: The maximum number of items to return in a search result. Default is `10`. -#### SPARQL Endpoint - -- **`enable_sparql_endpoint`**: Whether to enable the SPARQL endpoint. Default is `False`. - #### Temporal Configuration - **`temporal_predicate`**: The predicate used for temporal properties. Default is `sdo:temporal`. diff --git a/prez/repositories/remote_sparql.py b/prez/repositories/remote_sparql.py index 47bd3148..d18c4b31 100755 --- a/prez/repositories/remote_sparql.py +++ b/prez/repositories/remote_sparql.py @@ -62,16 +62,21 @@ async def sparql( ): """Sends a starlette Request object (containing a SPARQL query in the URL parameters) to a proxied SPARQL endpoint.""" - # TODO: This only supports SPARQL GET requests because the query is sent as a query parameter. - query_escaped_as_bytes = f"query={quote_plus(query)}".encode("utf-8") - - # TODO: Global app settings should be passed in as a function argument. - url = httpx.URL(url=settings.sparql_endpoint, query=query_escaped_as_bytes) headers = [] for header in raw_headers: if header[0] != b"host": headers.append(header) + + # TODO: Global app settings should be passed in as a function argument. + if method == 'GET': + query_escaped_as_bytes = f"query={quote_plus(query)}".encode("utf-8") + url = httpx.URL(url=settings.sparql_endpoint, query=query_escaped_as_bytes) + rp_req = self.async_client.build_request(method, url, headers=headers) + else: + url = httpx.URL(url=settings.sparql_endpoint) + rp_req = self.async_client.build_request(method, url, headers=headers, data={'query': query}) + headers.append((b"host", str(url.host).encode("utf-8"))) - rp_req = self.async_client.build_request(method, url, headers=headers) + return await self.async_client.send(rp_req, stream=True)