pub struct RequestBuilder { /* private fields */ }Expand description
A request builder returned by RotatingClient::request.
This wraps reqwest::RequestBuilder instead of returning it directly:
the reqwest idiom of calling .send() on a plain RequestBuilder would
send the request from the direct client, with no proxy rotation, rate
limiting or retries — silently doing the one thing a RotatingClient
exists to prevent. Call send here instead; it routes
through the same retry loop as RotatingClient::get.
into_inner is the escape hatch for the rare case
you want the plain builder anyway.
Implementations§
Source§impl RequestBuilder
impl RequestBuilder
Sourcepub fn header<K, V>(self, key: K, value: V) -> Selfwhere
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<Error>,
pub fn header<K, V>(self, key: K, value: V) -> Selfwhere
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<Error>,
Adds a header. See reqwest::RequestBuilder::header.
Sourcepub fn headers(self, headers: HeaderMap) -> Self
pub fn headers(self, headers: HeaderMap) -> Self
Adds a set of headers, merged into any already set. See
reqwest::RequestBuilder::headers.
Sourcepub fn basic_auth<U, P>(self, username: U, password: Option<P>) -> Self
pub fn basic_auth<U, P>(self, username: U, password: Option<P>) -> Self
Enables HTTP basic authentication. See
reqwest::RequestBuilder::basic_auth.
Sourcepub fn bearer_auth<T>(self, token: T) -> Selfwhere
T: Display,
pub fn bearer_auth<T>(self, token: T) -> Selfwhere
T: Display,
Enables HTTP bearer authentication. See
reqwest::RequestBuilder::bearer_auth.
Sourcepub fn body<T: Into<Body>>(self, body: T) -> Self
pub fn body<T: Into<Body>>(self, body: T) -> Self
Sets the request body. See reqwest::RequestBuilder::body.
Sourcepub fn timeout(self, timeout: Duration) -> Self
pub fn timeout(self, timeout: Duration) -> Self
Enables a per-request timeout, overriding the client’s default. See
reqwest::RequestBuilder::timeout.
Sourcepub fn version(self, version: Version) -> Self
pub fn version(self, version: Version) -> Self
Sets the HTTP version. See reqwest::RequestBuilder::version.
Sourcepub fn query<T: Serialize + ?Sized>(self, query: &T) -> Self
pub fn query<T: Serialize + ?Sized>(self, query: &T) -> Self
Appends query parameters to the URL. See
reqwest::RequestBuilder::query.
Sourcepub fn form<T: Serialize + ?Sized>(self, form: &T) -> Self
pub fn form<T: Serialize + ?Sized>(self, form: &T) -> Self
Sends a url-encoded form body. See
reqwest::RequestBuilder::form.
Sourcepub fn json<T: Serialize + ?Sized>(self, json: &T) -> Self
pub fn json<T: Serialize + ?Sized>(self, json: &T) -> Self
Sends a JSON body. Needs the json feature. See
reqwest::RequestBuilder::json.
Sourcepub fn multipart(self, form: Form) -> Self
pub fn multipart(self, form: Form) -> Self
Sends a multipart/form-data body. Needs the multipart feature.
See reqwest::RequestBuilder::multipart.
Sourcepub fn build(self) -> Result<Request, Error>
pub fn build(self) -> Result<Request, Error>
Builds the Request without sending it.
§Errors
Returns Error::Reqwest if the request could not be built, e.g.
an invalid header or an unserialisable query,
form or json body.
Sourcepub async fn send(self) -> Result<Response, Error>
pub async fn send(self) -> Result<Response, Error>
Sends the request, applying rate limiting, proxy rotation, and
retries — the same path as RotatingClient::get.
§Errors
Returns Error::Reqwest when the request cannot be built or when
the last attempt fails after the retries are used up; see
Error for the full set.
Sourcepub fn into_inner(self) -> RequestBuilder
pub fn into_inner(self) -> RequestBuilder
Escapes to the plain reqwest::RequestBuilder. Its own .send()
bypasses rate limiting, proxy rotation and retries, sending directly
with no proxy; pass it to RotatingClient::send to get them back.