diff --git a/server/src/main.rs b/server/src/main.rs index 1264f132..630e9db6 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -1531,19 +1531,24 @@ fn web_load_graph( format: GraphFormat, to_graph_name: GraphNameRef<'_>, ) -> Result<(), HttpError> { + let base_iri = if let GraphNameRef::NamedNode(graph_name) = to_graph_name { + Some(graph_name.as_str()) + } else { + None + }; if url_query_parameter(request, "no_transaction").is_some() { web_bulk_loader(store, request).load_graph( BufReader::new(request.body_mut()), format, to_graph_name, - None, + base_iri, ) } else { store.load_graph( BufReader::new(request.body_mut()), format, to_graph_name, - None, + base_iri, ) } .map_err(loader_to_http_error) @@ -2367,6 +2372,53 @@ mod tests { ) } + #[test] + fn graph_store_base_url() -> Result<()> { + let server = ServerTest::new()?; + + // POST + let request = Request::builder( + Method::POST, + "http://localhost/store?graph=http://example.com".parse()?, + ) + .with_header(HeaderName::CONTENT_TYPE, "text/turtle")? + .with_body("<> ."); + server.test_status(request, Status::NO_CONTENT)?; + + // GET + let request = Request::builder( + Method::GET, + "http://localhost/store?graph=http://example.com".parse()?, + ) + .with_header(HeaderName::ACCEPT, "application/n-triples")? + .build(); + server.test_body( + request, + " .\n", + )?; + + // PUT + let request = Request::builder( + Method::PUT, + "http://localhost/store?graph=http://example.com".parse()?, + ) + .with_header(HeaderName::CONTENT_TYPE, "text/turtle")? + .with_body("<> ."); + server.test_status(request, Status::NO_CONTENT)?; + + // GET + let request = Request::builder( + Method::GET, + "http://localhost/store?graph=http://example.com".parse()?, + ) + .with_header(HeaderName::ACCEPT, "application/n-triples")? + .build(); + server.test_body( + request, + " .\n", + ) + } + #[test] fn graph_store_protocol() -> Result<()> { // Tests from https://www.w3.org/2009/sparql/docs/tests/data-sparql11/http-rdf-update/