Skip to main content

ReqwestTransport

Struct ReqwestTransport 

Source
pub struct ReqwestTransport { /* private fields */ }
Available on crate feature reqwest only.
Expand description

An HttpTransport backed by reqwest.

§Redirects

The client new builds never follows a redirect: the 3xx response comes back as it is, and the bundled providers report it as an allama::Error::UnexpectedResponse naming the target host (redirect_error). An LLM API never answers a request with a redirect, and following one is unsafe: reqwest strips only Authorization (and cookies) on a redirect to another host, so x-api-key, x-goog-api-key, api-key and gateway credential headers would reach the new host, a 307 or 308 would replay the prompt to it, and an https to http downgrade would be followed. A redirect would also bypass any allowlist the application checks a base URL against.

A client you pass to from_client or from_middleware (feature reqwest-middleware) keeps its own redirect policy, which is reqwest’s default (up to 10 redirects) unless you set one: build it with .redirect(reqwest::redirect::Policy::none()) to keep this guarantee. On wasm32, reqwest sends through the host’s fetch, whose redirect handling applies and cannot be changed from here.

With the reqwest-middleware feature, requests go through a reqwest-middleware client (from_middleware takes your own); the http-tracing feature also adds reqwest_tracing::TracingMiddleware to the clients new and from_client build.

Clone is cheap: reqwest clients are reference counted.

Implementations§

Source§

impl ReqwestTransport

Source

pub fn new() -> Self

A transport with a default reqwest client that never follows redirects (see Redirects), with a DEFAULT_CONNECT_TIMEOUT (both except on wasm32).

With the rustls-ring feature, it first installs rustls’ ring crypto provider as the process default, unless the application installed one. A client you build yourself for from_client needs a provider installed the same way (rustls::crypto::ring::default_provider().install_default()) before it is built.

§Panics

When the TLS backend cannot be initialized, like reqwest::Client::new.

Source

pub fn from_client(client: Client) -> Self

A transport over client, whose timeouts, redirect policy and other settings are used as they are (wrapped with tracing middleware under http-tracing). Unlike new’s, a client from reqwest::Client::new() follows redirects: see Redirects.

use std::time::Duration;
use allama_http::ReqwestTransport;

let client = reqwest::Client::builder()
    .redirect(reqwest::redirect::Policy::none())
    .connect_timeout(Duration::from_secs(5))
    .build()?;
let transport = ReqwestTransport::from_client(client);
Source

pub fn from_middleware(client: ClientWithMiddleware) -> Self

Available on crate feature reqwest-middleware only.

A transport over a middleware client, used unchanged (no tracing middleware is added, even under http-tracing), its redirect policy included: see Redirects.

Trait Implementations§

Source§

impl Clone for ReqwestTransport

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ReqwestTransport

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ReqwestTransport

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl HttpTransport for ReqwestTransport

Source§

fn send(&self, request: HttpRequest) -> SendFuture<'_>

Send request.

Auto Trait Implementations§

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<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