Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

A high-level HTTP/3-over-SCION client: URL in, response out.

The client owns everything between a URL and a connection: SCION connectivity, DNS resolution, a connection pool, and timeouts. It is cheap to construct and intended to be a long-lived value shared across an application: it is Send + Sync, and requests borrow it immutably.

use scion_http3::{Client, Config};

const MAX_BODY_SIZE: usize = 1 << 20;

let client = Client::new(Config::new("https://endhost-api.example.org".parse()?));
let response = client.get("https://chat.example.org/rooms").await?;
let (body, _trailers) = response.text(Some(MAX_BODY_SIZE)).await?;

Implementations§

Source§

impl Client

Source

pub fn new(config: Config) -> Self

Creates a client. Performs no I/O: connectivity is built lazily by the first request (or by warm_up).

Source

pub async fn request(&self, request: Request) -> Result<Response, Error>

Issues a request and returns the response once its head has arrived.

The whole call, building connectivity if needed, resolving the origin, establishing or reusing its connection, and waiting for the response head, runs under the request timeout (the per-request override, or the configured default). Collecting the body on the returned Response runs under the remainder of the same deadline.

If establishing a connection through a pooled client fails, the origin is re-resolved and re-established once and the request re-issued. This is safe for non-idempotent requests: establishment failure means nothing reached the wire, and bodies are buffered and thus replayable. Errors after the request reached the wire are never retried here; see Error::is_retryable for what the caller may retry.

Source

pub async fn get(&self, url: impl IntoUrl) -> Result<Response, Error>

Issues a GET request to url. Shorthand for building a Request with defaults and calling request.

Source

pub async fn post( &self, url: impl IntoUrl, body: impl Into<Bytes>, ) -> Result<Response, Error>

Issues a POST request with the given body to url. Shorthand for building a Request with defaults and calling request.

Source

pub async fn connect(&self, authority: &Authority) -> Result<Tunnel, Error>

Opens a CONNECT tunnel to authority.

The connection to the authority is resolved and pooled like the one of a request to https://host:port/. The call runs under the request timeout up to the response head; the open Tunnel has no deadline. A non-2xx response is Error::TunnelRefused.

Source

pub async fn connect_via( &self, via: &Authority, target: &Authority, ) -> Result<Tunnel, Error>

Opens a CONNECT tunnel to target through the tunnel server at via.

The client dials via and sends target as the CONNECT authority. Otherwise it works like connect.

Source

pub async fn connect_via_unverified( &self, via: &Authority, target: &Authority, ) -> Result<Tunnel, Error>

Like connect_via, but does not verify the certificate of via.

The caller must authenticate target inside the tunnel, for example with TLS.

Source

pub async fn warm_up(&self, url: impl IntoUrl) -> Result<(), Error>

Pre-establishes connectivity to url’s origin: builds the stack if needed, resolves the origin, and performs the QUIC handshake, so the first request pays none of it. Runs under the connect timeout (plus stack build time).

Source

pub fn reset(&self)

Marks connectivity stale: the next request tears down the current connections and rebuilds the stack, discovery, and resolver state.

Call this when the network below the client changed (for example on a platform network-change signal). Never blocks; if the rebuild fails, the failing request reports the build error and the next request retries the rebuild.

Source

pub async fn close(&self)

Closes the client: tears down all pooled connections, faulting in-flight requests promptly. Subsequent requests fail with Error::Closed. Idempotent.

Auto Trait Implementations§

§

impl !Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl !UnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnsafeUnpin for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more