pub struct ReqwestTransport { /* private fields */ }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
impl ReqwestTransport
Sourcepub fn new() -> Self
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.
Sourcepub fn from_client(client: Client) -> Self
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);Sourcepub fn from_middleware(client: ClientWithMiddleware) -> Self
Available on crate feature reqwest-middleware only.
pub fn from_middleware(client: ClientWithMiddleware) -> Self
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
impl Clone for ReqwestTransport
Source§impl Debug for ReqwestTransport
impl Debug for ReqwestTransport
Source§impl Default for ReqwestTransport
impl Default for ReqwestTransport
Source§impl HttpTransport for ReqwestTransport
impl HttpTransport for ReqwestTransport
Source§fn send(&self, request: HttpRequest) -> SendFuture<'_>
fn send(&self, request: HttpRequest) -> SendFuture<'_>
request.