HTTP client: adds an option to allow redirections

pull/216/head
Tpt 3 years ago
parent d9487fd9f5
commit 1f7e59dde7
  1. 3
      lib/src/sparql/http/simple.rs
  2. 19
      lib/src/sparql/mod.rs
  3. 4
      lib/src/sparql/service.rs
  4. 5
      lib/src/sparql/update.rs

@ -7,11 +7,12 @@ pub struct Client {
}
impl Client {
pub fn new(timeout: Option<Duration>) -> Self {
pub fn new(timeout: Option<Duration>, redirection_limit: usize) -> Self {
let mut client = oxhttp::Client::new();
if let Some(timeout) = timeout {
client.set_global_timeout(timeout);
}
client.set_redirection_limit(redirection_limit);
client
.set_user_agent(concat!("Oxigraph/", env!("CARGO_PKG_VERSION")))
.unwrap();

@ -127,6 +127,7 @@ pub struct QueryOptions {
service_handler: Option<Rc<dyn ServiceHandler<Error = EvaluationError>>>,
custom_functions: HashMap<NamedNode, Rc<dyn Fn(&[Term]) -> Option<Term>>>,
http_timeout: Option<Duration>,
http_redirection_limit: usize,
}
impl QueryOptions {
@ -148,7 +149,7 @@ impl QueryOptions {
self
}
/// Sets a timeout for HTTP requests done during SPARQL evaluation
/// Sets a timeout for HTTP requests done during SPARQL evaluation.
#[cfg(feature = "http_client")]
#[inline]
#[must_use]
@ -157,6 +158,17 @@ impl QueryOptions {
self
}
/// Sets an upper bound of the number of HTTP redirection followed per HTTP request done during SPARQL evaluation.
///
/// By default this value is `0`.
#[cfg(feature = "http_client")]
#[inline]
#[must_use]
pub fn with_http_redirection_limit(mut self, redirection_limit: usize) -> Self {
self.http_redirection_limit = redirection_limit;
self
}
/// Adds a custom SPARQL evaluation function.
///
/// Example with a function serializing terms to N-Triples:
@ -192,7 +204,10 @@ impl QueryOptions {
fn service_handler(&self) -> Rc<dyn ServiceHandler<Error = EvaluationError>> {
self.service_handler.clone().unwrap_or_else(|| {
if cfg!(feature = "http_client") {
Rc::new(service::SimpleServiceHandler::new(self.http_timeout))
Rc::new(service::SimpleServiceHandler::new(
self.http_timeout,
self.http_redirection_limit,
))
} else {
Rc::new(EmptyServiceHandler)
}

@ -97,9 +97,9 @@ pub struct SimpleServiceHandler {
}
impl SimpleServiceHandler {
pub fn new(http_timeout: Option<Duration>) -> Self {
pub fn new(http_timeout: Option<Duration>, http_redirection_limit: usize) -> Self {
Self {
client: Client::new(http_timeout),
client: Client::new(http_timeout, http_redirection_limit),
}
}
}

@ -31,7 +31,10 @@ pub fn evaluate_update<'a, 'b: 'a>(
transaction,
base_iri: update.inner.base_iri.clone().map(Rc::new),
options: options.clone(),
client: Client::new(options.query_options.http_timeout),
client: Client::new(
options.query_options.http_timeout,
options.query_options.http_redirection_limit,
),
}
.eval_all(&update.inner.operations, &update.using_datasets)
}

Loading…
Cancel
Save