|
|
@ -132,7 +132,7 @@ fn handle_request(request: &mut Request, store: Store) -> Response { |
|
|
|
.unwrap() |
|
|
|
.unwrap() |
|
|
|
.with_body(LOGO), |
|
|
|
.with_body(LOGO), |
|
|
|
("/query", "GET") => { |
|
|
|
("/query", "GET") => { |
|
|
|
configure_and_evaluate_sparql_query(store, url_query(request), None, request) |
|
|
|
configure_and_evaluate_sparql_query(store, &[url_query(request)], None, request) |
|
|
|
} |
|
|
|
} |
|
|
|
("/query", "POST") => { |
|
|
|
("/query", "POST") => { |
|
|
|
if let Some(content_type) = content_type(request) { |
|
|
|
if let Some(content_type) = content_type(request) { |
|
|
@ -145,8 +145,12 @@ fn handle_request(request: &mut Request, store: Store) -> Response { |
|
|
|
{ |
|
|
|
{ |
|
|
|
return bad_request(e); |
|
|
|
return bad_request(e); |
|
|
|
} |
|
|
|
} |
|
|
|
let encoded = url_query(request); |
|
|
|
configure_and_evaluate_sparql_query( |
|
|
|
configure_and_evaluate_sparql_query(store, encoded, Some(buffer), request) |
|
|
|
store, |
|
|
|
|
|
|
|
&[url_query(request)], |
|
|
|
|
|
|
|
Some(buffer), |
|
|
|
|
|
|
|
request, |
|
|
|
|
|
|
|
) |
|
|
|
} else if content_type == "application/x-www-form-urlencoded" { |
|
|
|
} else if content_type == "application/x-www-form-urlencoded" { |
|
|
|
let mut buffer = Vec::new(); |
|
|
|
let mut buffer = Vec::new(); |
|
|
|
if let Err(e) = request |
|
|
|
if let Err(e) = request |
|
|
@ -156,7 +160,12 @@ fn handle_request(request: &mut Request, store: Store) -> Response { |
|
|
|
{ |
|
|
|
{ |
|
|
|
return bad_request(e); |
|
|
|
return bad_request(e); |
|
|
|
} |
|
|
|
} |
|
|
|
configure_and_evaluate_sparql_query(store, buffer, None, request) |
|
|
|
configure_and_evaluate_sparql_query( |
|
|
|
|
|
|
|
store, |
|
|
|
|
|
|
|
&[url_query(request), &buffer], |
|
|
|
|
|
|
|
None, |
|
|
|
|
|
|
|
request, |
|
|
|
|
|
|
|
) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
unsupported_media_type(&content_type) |
|
|
|
unsupported_media_type(&content_type) |
|
|
|
} |
|
|
|
} |
|
|
@ -177,7 +186,7 @@ fn handle_request(request: &mut Request, store: Store) -> Response { |
|
|
|
} |
|
|
|
} |
|
|
|
configure_and_evaluate_sparql_update( |
|
|
|
configure_and_evaluate_sparql_update( |
|
|
|
store, |
|
|
|
store, |
|
|
|
url_query(request), |
|
|
|
&[url_query(request)], |
|
|
|
Some(buffer), |
|
|
|
Some(buffer), |
|
|
|
request, |
|
|
|
request, |
|
|
|
) |
|
|
|
) |
|
|
@ -190,7 +199,12 @@ fn handle_request(request: &mut Request, store: Store) -> Response { |
|
|
|
{ |
|
|
|
{ |
|
|
|
return bad_request(e); |
|
|
|
return bad_request(e); |
|
|
|
} |
|
|
|
} |
|
|
|
configure_and_evaluate_sparql_update(store, buffer, None, request) |
|
|
|
configure_and_evaluate_sparql_update( |
|
|
|
|
|
|
|
store, |
|
|
|
|
|
|
|
&[url_query(request), &buffer], |
|
|
|
|
|
|
|
None, |
|
|
|
|
|
|
|
request, |
|
|
|
|
|
|
|
) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
unsupported_media_type(&content_type) |
|
|
|
unsupported_media_type(&content_type) |
|
|
|
} |
|
|
|
} |
|
|
@ -481,20 +495,21 @@ fn resolve_with_base(request: &Request, url: &str) -> Result<NamedNode, Response |
|
|
|
)) |
|
|
|
)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn url_query(request: &Request) -> Vec<u8> { |
|
|
|
fn url_query(request: &Request) -> &[u8] { |
|
|
|
request.url().query().unwrap_or("").as_bytes().to_vec() |
|
|
|
request.url().query().unwrap_or("").as_bytes() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn configure_and_evaluate_sparql_query( |
|
|
|
fn configure_and_evaluate_sparql_query( |
|
|
|
store: Store, |
|
|
|
store: Store, |
|
|
|
encoded: Vec<u8>, |
|
|
|
encoded: &[&[u8]], |
|
|
|
mut query: Option<String>, |
|
|
|
mut query: Option<String>, |
|
|
|
request: &Request, |
|
|
|
request: &Request, |
|
|
|
) -> Response { |
|
|
|
) -> Response { |
|
|
|
let mut default_graph_uris = Vec::new(); |
|
|
|
let mut default_graph_uris = Vec::new(); |
|
|
|
let mut named_graph_uris = Vec::new(); |
|
|
|
let mut named_graph_uris = Vec::new(); |
|
|
|
let mut use_default_graph_as_union = false; |
|
|
|
let mut use_default_graph_as_union = false; |
|
|
|
for (k, v) in form_urlencoded::parse(&encoded) { |
|
|
|
for encoded in encoded { |
|
|
|
|
|
|
|
for (k, v) in form_urlencoded::parse(encoded) { |
|
|
|
match k.as_ref() { |
|
|
|
match k.as_ref() { |
|
|
|
"query" => { |
|
|
|
"query" => { |
|
|
|
if query.is_some() { |
|
|
|
if query.is_some() { |
|
|
@ -508,6 +523,7 @@ fn configure_and_evaluate_sparql_query( |
|
|
|
_ => (), |
|
|
|
_ => (), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
if let Some(query) = query { |
|
|
|
if let Some(query) = query { |
|
|
|
evaluate_sparql_query( |
|
|
|
evaluate_sparql_query( |
|
|
|
store, |
|
|
|
store, |
|
|
@ -646,14 +662,15 @@ fn evaluate_sparql_query( |
|
|
|
|
|
|
|
|
|
|
|
fn configure_and_evaluate_sparql_update( |
|
|
|
fn configure_and_evaluate_sparql_update( |
|
|
|
store: Store, |
|
|
|
store: Store, |
|
|
|
encoded: Vec<u8>, |
|
|
|
encoded: &[&[u8]], |
|
|
|
mut update: Option<String>, |
|
|
|
mut update: Option<String>, |
|
|
|
request: &Request, |
|
|
|
request: &Request, |
|
|
|
) -> Response { |
|
|
|
) -> Response { |
|
|
|
let mut use_default_graph_as_union = false; |
|
|
|
let mut use_default_graph_as_union = false; |
|
|
|
let mut default_graph_uris = Vec::new(); |
|
|
|
let mut default_graph_uris = Vec::new(); |
|
|
|
let mut named_graph_uris = Vec::new(); |
|
|
|
let mut named_graph_uris = Vec::new(); |
|
|
|
for (k, v) in form_urlencoded::parse(&encoded) { |
|
|
|
for encoded in encoded { |
|
|
|
|
|
|
|
for (k, v) in form_urlencoded::parse(encoded) { |
|
|
|
match k.as_ref() { |
|
|
|
match k.as_ref() { |
|
|
|
"update" => { |
|
|
|
"update" => { |
|
|
|
if update.is_some() { |
|
|
|
if update.is_some() { |
|
|
@ -667,6 +684,7 @@ fn configure_and_evaluate_sparql_update( |
|
|
|
_ => (), |
|
|
|
_ => (), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
if let Some(update) = update { |
|
|
|
if let Some(update) = update { |
|
|
|
evaluate_sparql_update( |
|
|
|
evaluate_sparql_update( |
|
|
|
store, |
|
|
|
store, |
|
|
@ -1166,6 +1184,35 @@ mod tests { |
|
|
|
"s,p,o\r\nhttp://example.com,http://example.com,http://example.com", |
|
|
|
"s,p,o\r\nhttp://example.com,http://example.com,http://example.com", |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn get_query_union_graph_in_url_and_urlencoded() { |
|
|
|
|
|
|
|
let server = ServerTest::new(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let request = Request::builder(Method::PUT, "http://localhost/store/1".parse().unwrap()) |
|
|
|
|
|
|
|
.with_header(HeaderName::CONTENT_TYPE, "text/turtle") |
|
|
|
|
|
|
|
.unwrap() |
|
|
|
|
|
|
|
.with_body("<http://example.com> <http://example.com> <http://example.com> ."); |
|
|
|
|
|
|
|
server.test_status(request, Status::CREATED); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let request = Request::builder( |
|
|
|
|
|
|
|
Method::POST, |
|
|
|
|
|
|
|
"http://localhost/query?union-default-graph" |
|
|
|
|
|
|
|
.parse() |
|
|
|
|
|
|
|
.unwrap(), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.with_header( |
|
|
|
|
|
|
|
HeaderName::CONTENT_TYPE, |
|
|
|
|
|
|
|
"application/x-www-form-urlencoded", |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.unwrap() |
|
|
|
|
|
|
|
.with_header(HeaderName::ACCEPT, "text/csv") |
|
|
|
|
|
|
|
.unwrap() |
|
|
|
|
|
|
|
.with_body("query=SELECT%20?s%20?p%20?o%20WHERE%20{%20?s%20?p%20?o%20}"); |
|
|
|
|
|
|
|
server.test_body( |
|
|
|
|
|
|
|
request, |
|
|
|
|
|
|
|
"s,p,o\r\nhttp://example.com,http://example.com,http://example.com", |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn get_query_union_graph_and_default_graph() { |
|
|
|
fn get_query_union_graph_and_default_graph() { |
|
|
|