pub struct RequestOptions { /* private fields */ }Expand description
Extra headers and query parameters for one call, applied after everything the generated code sets.
A generated operation takes them with .options(&options); RequestBuilder::options
applies them to a request of your own. One value can be reused for many calls.
- A header replaces every value the request has under the same name: generated headers, authentication and
Content-Typeincluded. A name set twice on the options keeps both values (seeRequestOptions::headers). - Query parameters are appended after the generated ones; a name the request already has is sent twice.
use timvw_rust_runtime::RequestOptions;
let options = RequestOptions::new()
.header("x-request-source", "batch")?
.query(&[("trace", "1")])?;
assert_eq!(options.header_map()["x-request-source"], "batch");
assert_eq!(options.query_pairs(), [("trace".to_owned(), "1".to_owned())]);Implementations§
Source§impl RequestOptions
impl RequestOptions
Sourcepub fn header<K, V>(self, name: K, value: V) -> Result<Self, Error>where
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, name: K, value: V) -> Result<Self, Error>where
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<Error>,
Sets a header, replacing a value set before under the same name. Fails, with an error whose
is_builder() is true, on an invalid name or value.
Sourcepub fn headers(self, headers: HeaderMap) -> Self
pub fn headers(self, headers: HeaderMap) -> Self
Adds every header of a map, replacing the values set before under its names. A name with several values in
headers keeps them all, and so does the request they are applied to.
Sourcepub fn query<T: Serialize + ?Sized>(self, query: &T) -> Result<Self, Error>
pub fn query<T: Serialize + ?Sized>(self, query: &T) -> Result<Self, Error>
Appends query parameters, serialized as application/x-www-form-urlencoded: a sequence of pairs, a map or a
struct, as RequestBuilder::query takes them. Fails, with an error whose
is_builder() is true, on a value that is not a flat list of pairs.
Sourcepub fn header_map(&self) -> &HeaderMap
pub fn header_map(&self) -> &HeaderMap
The headers.
Sourcepub fn query_pairs(&self) -> &[(String, String)]
pub fn query_pairs(&self) -> &[(String, String)]
The query parameters, decoded, in order.