pub struct Connector<R: Runtime> { /* private fields */ }
Expand description
Main entrypoint: Object for making HTTP/S requests through Tor.
This type embodies an arti_client::TorClient
and implements [ureq::unversioned::transport::Connector
],
allowing HTTP/HTTPS requests to be made with ureq
over Tor.
Also bridges between async I/O (in Arti and Tokio) and sync I/O (in ureq
).
§A Connector
object can be constructed in different ways.
§1. Use Connector::new
to create a Connector
with a default TorClient
.
let connector = arti_ureq::Connector::new().expect("Failed to create Connector.");
§2. Use Connector::with_tor_client
to create a Connector
with a specific TorClient
.
let tor_client = arti_client::TorClient::with_runtime(
tor_rtcompat::PreferredRuntime::create().expect("Failed to create runtime.")
)
.create_unbootstrapped()
.expect("Error creating Tor Client.");
let connector = arti_ureq::Connector::with_tor_client(tor_client);
§3. Use Connector::builder
to create a ConnectorBuilder
and configure a Connector
with it.
let connector = arti_ureq::Connector::<tor_rtcompat::PreferredRuntime>::builder()
.expect("Failed to create ConnectorBuilder.")
.build()
.expect("Failed to create Connector.");
§Usage of Connector
.
A Connector
can be used to retrieve an [ureq::Agent
] with Connector::agent
or pass the Connector
to [ureq::Agent::with_parts
] along with a custom [ureq::config::Config
] and a resolver
obtained from Connector::resolver
to retrieve a more configurable [ureq::Agent
].
§Retrieve an ureq::Agent
.
let connector = arti_ureq::Connector::new().expect("Failed to create Connector.");
let ureq_agent = connector.agent();
§Pass as argument to ureq::Agent::with_parts
.
We highly advice only using Resolver
instead of e.g ureq
’s [ureq::unversioned::resolver::DefaultResolver
] to avoid DNS leaks.
let connector = arti_ureq::Connector::new().expect("Failed to create Connector.");
let resolver = connector.resolver();
let ureq_agent = ureq::Agent::with_parts(
ureq::config::Config::default(),
connector,
resolver,
);
Implementations§
Source§impl<R: Runtime + ToplevelBlockOn> Connector<R>
impl<R: Runtime + ToplevelBlockOn> Connector<R>
Sourcepub fn with_tor_client(client: TorClient<R>) -> Connector<R>
pub fn with_tor_client(client: TorClient<R>) -> Connector<R>
Creates new instance with the provided arti_client::TorClient
.
Source§impl Connector<PreferredRuntime>
impl Connector<PreferredRuntime>
Sourcepub fn new() -> Result<Self, Error>
pub fn new() -> Result<Self, Error>
Returns new Connector
with default values.
To configure a non-default Connector
,
use ConnectorBuilder
.
Warning: This method creates a default arti_client::TorClient
. Using multiple concurrent
instances of TorClient
is not recommended. Most programs should create a single TorClient
centrally.
Source§impl<R: Runtime + ToplevelBlockOn> Connector<R>
impl<R: Runtime + ToplevelBlockOn> Connector<R>
Sourcepub fn resolver(&self) -> Resolver<R>
pub fn resolver(&self) -> Resolver<R>
Returns instance of Resolver
implementing trait [ureq::unversioned::resolver::Resolver
].
Sourcepub fn agent(self) -> Agent
pub fn agent(self) -> Agent
Returns instance of [ureq::Agent
].
Equivalent to using [ureq::Agent::with_parts
] with the default [ureq::config::Config
]
and this Connector
and the resolver obtained from Connector::resolver()
.
§Example
let ureq_agent = arti_ureq::Connector::new()
.expect("Failed to create Connector")
.agent();
// Use the agent to make a request.
ureq_agent
.get("https://check.torproject.org/api/ip")
.call()
.expect("Failed to make request.");
Sourcepub fn agent_with_ureq_config(self, config: Config) -> Result<Agent, Error>
pub fn agent_with_ureq_config(self, config: Config) -> Result<Agent, Error>
Returns instance of [ureq::Agent
] using the provided [ureq::config::Config
].
Equivalent to Connector::agent
but allows the user to provide a custom [ureq::config::Config
].
Source§impl<R: Runtime> Connector<R>
Implementation to make ConnectorBuilder
accessible from Connector
.
impl<R: Runtime> Connector<R>
Implementation to make ConnectorBuilder
accessible from Connector
.
§Example
let rt = tor_rtcompat::PreferredRuntime::create().expect("Failed to create runtime.");
let tls_provider = arti_ureq::get_default_tls_provider();
let client = arti_client::TorClient::with_runtime(rt.clone())
.create_unbootstrapped()
.expect("Error creating Tor Client.");
let builder = arti_ureq::ConnectorBuilder::<tor_rtcompat::PreferredRuntime>::new()
.expect("Failed to create ConnectorBuilder.")
.tor_client(client)
.tls_provider(tls_provider);
let arti_connector = builder.build();
Sourcepub fn builder() -> Result<ConnectorBuilder<PreferredRuntime>, Error>
pub fn builder() -> Result<ConnectorBuilder<PreferredRuntime>, Error>
Returns new ConnectorBuilder
with default values.
Trait Implementations§
Source§impl<R: Runtime + ToplevelBlockOn> Connector for Connector<R>
impl<R: Runtime + ToplevelBlockOn> Connector for Connector<R>
Auto Trait Implementations§
impl<R> !Freeze for Connector<R>
impl<R> !RefUnwindSafe for Connector<R>
impl<R> Send for Connector<R>
impl<R> Sync for Connector<R>
impl<R> Unpin for Connector<R>where
R: Unpin,
impl<R> !UnwindSafe for Connector<R>
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
, which can then be
downcast
into Box<dyn ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
, which can then be further
downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.