pub struct RestTransport {
pub http: Arc<dyn HttpClient>,
pub policy: RetryPolicy,
pub response_header_timeout: Option<Duration>,
}Expand description
A provider’s REST transport: the HTTP client, the retry policy and the response-header timeout.
Fields§
§http: Arc<dyn HttpClient>The HTTP client.
policy: RetryPolicyThe retry policy.
response_header_timeout: Option<Duration>A timeout on each HttpClient::send (until the response headers):
DEFAULT_RESPONSE_HEADER_TIMEOUT when the provider built the client itself, None
for a caller’s client. It covers connecting and writing the request too, never a body;
the header fetch before send is outside it.
Implementations§
Source§impl RestTransport
impl RestTransport
Sourcepub async fn send(
&self,
uri: &Uri,
body: Bytes,
stream: bool,
headers: &dyn RequestHeaders,
timeout: CallTimeout,
) -> Result<RestReply, RestError>
pub async fn send( &self, uri: &Uri, body: Bytes, stream: bool, headers: &dyn RequestHeaders, timeout: CallTimeout, ) -> Result<RestReply, RestError>
POSTs body to uri with the policy’s retries and returns the response that ends
the call: send_method with Method::POST.
Sourcepub async fn send_method(
&self,
method: Method,
uri: &Uri,
body: Bytes,
stream: bool,
headers: &dyn RequestHeaders,
timeout: CallTimeout,
) -> Result<RestReply, RestError>
pub async fn send_method( &self, method: Method, uri: &Uri, body: Bytes, stream: bool, headers: &dyn RequestHeaders, timeout: CallTimeout, ) -> Result<RestReply, RestError>
Sends body to uri as a method request (an empty body for a GET or DELETE)
with the policy’s retries and returns the response that ends the call.
- Attempts:
policy.max_retries + 1. Each attempt fetchesheadersfirst. A header failure, a connection error and the response-header timeout are retried with backoff; after the last attempt they are returned (RestError::Headersor the provider’s error,RestError::Transport,RestError::ResponseHeaderTimeout). - A response is retried per
should_retry(a 2xx withx-should-retry: trueincluded) afterRetryPolicy::retry_delaywith its headers, unread; aRetryAfter::Stopmakes it the final response instead (the OpenAI SDK preserves it). - The final response’s body is read, unless the call streams and the status is < 400:
RestReply::Read, orRestReply::Streamingwith the live body. - A body that fails to read is retried with that response’s headers when
policy.retry_dropped_bodyandshould_retry_dropped_bodyallow it and attempts remain; otherwise it isRestError::DroppedBody. timeout: seeCallTimeout.- Every await is cancelled by dropping the future (no task is spawned).
Trait Implementations§
Source§impl Clone for RestTransport
impl Clone for RestTransport
Auto Trait Implementations§
impl !RefUnwindSafe for RestTransport
impl !UnwindSafe for RestTransport
impl Forget for RestTransport
impl Freeze for RestTransport
impl Move for RestTransport
impl Send for RestTransport
impl Sync for RestTransport
impl Unpin for RestTransport
impl UnsafeUnpin for RestTransport
Blanket Implementations§
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
Mutably borrows from an owned value. Read more