Struct Session

Source
pub struct Session { /* private fields */ }
Expand description

Session is a type that can carry settings over multiple requests. The settings applied to the Session are applied to every request created from this Session.

Session can be cloned cheaply and sent to other threads as it uses std::sync::Arc internally.

Implementations§

Source§

impl Session

Source

pub fn new() -> Session

Create a new Session with default settings.

Source

pub fn get<U>(&self, base_url: U) -> RequestBuilder
where U: AsRef<str>,

Create a new RequestBuilder with the GET method and this Session’s settings applied on it.

Source

pub fn post<U>(&self, base_url: U) -> RequestBuilder
where U: AsRef<str>,

Create a new RequestBuilder with the POST method and this Session’s settings applied on it.

Source

pub fn put<U>(&self, base_url: U) -> RequestBuilder
where U: AsRef<str>,

Create a new RequestBuilder with the PUT method and this Session’s settings applied on it.

Source

pub fn delete<U>(&self, base_url: U) -> RequestBuilder
where U: AsRef<str>,

Create a new RequestBuilder with the DELETE method and this Session’s settings applied on it.

Source

pub fn head<U>(&self, base_url: U) -> RequestBuilder
where U: AsRef<str>,

Create a new RequestBuilder with the HEAD method and this Session’s settings applied on it.

Source

pub fn options<U>(&self, base_url: U) -> RequestBuilder
where U: AsRef<str>,

Create a new RequestBuilder with the OPTIONS method and this Session’s settings applied on it.

Source

pub fn patch<U>(&self, base_url: U) -> RequestBuilder
where U: AsRef<str>,

Create a new RequestBuilder with the PATCH method and this Session’s settings applied on it.

Source

pub fn trace<U>(&self, base_url: U) -> RequestBuilder
where U: AsRef<str>,

Create a new RequestBuilder with the TRACE method and this Session’s settings applied on it.

Source

pub fn header<H, V>(&mut self, header: H, value: V)

Modify a header for this Session.

If the header is already present, the value will be replaced. If you wish to append a new header, use header_append.

§Panics

This method will panic if the value is invalid.

Source

pub fn header_append<H, V>(&mut self, header: H, value: V)

Append a new header for this Session.

The new header is always appended to the headers, even if the header already exists.

§Panics

This method will panic if the value is invalid.

Source

pub fn try_header<H, V>(&mut self, header: H, value: V) -> Result<()>

Modify a header for this Session.

If the header is already present, the value will be replaced. If you wish to append a new header, use header_append.

Source

pub fn try_header_append<H, V>(&mut self, header: H, value: V) -> Result<()>

Append a new header to this Session.

The new header is always appended to the headers, even if the header already exists.

Source

pub fn max_headers(&mut self, max_headers: usize)

Set the maximum number of headers accepted in responses to requests created from this Session.

The default is 100.

Source

pub fn max_redirections(&mut self, max_redirections: u32)

Set the maximum number of redirections the requests created from this Session can perform.

The default is 5.

Source

pub fn follow_redirects(&mut self, follow_redirects: bool)

Sets if requests created from this Session should follow redirects, 3xx codes.

This value defaults to true.

Source

pub fn connect_timeout(&mut self, connect_timeout: Duration)

Sets a connect timeout for requests created from this Session.

The default is 30 seconds.

Source

pub fn read_timeout(&mut self, read_timeout: Duration)

Sets a read timeout for requests created from this Session.

The default is 30 seconds.

Source

pub fn timeout(&mut self, timeout: Duration)

Sets a timeout for the maximum duration of requests created from this Session.

Applies after a TCP connection is established. Defaults to no timeout.

Source

pub fn proxy_settings(&mut self, proxy_settings: ProxySettings)

Sets the proxy settigns for requests created from this Session.

If left untouched, the defaults are to use system proxy settings found in environment variables.

Source

pub fn default_charset(&mut self, default_charset: Option<Charset>)

Set the default charset to use while parsing the responses of requests created from this Session.

If the response does not say which charset it uses, this charset will be used to decode the requests. This value defaults to None, in which case ISO-8859-1 is used.

Source

pub fn allow_compression(&mut self, allow_compression: bool)

Sets if requests created from this Session will announce that they accept compression.

This value defaults to true. Note that this only lets the browser know that the requests support compression, the server might choose not to compress the content.

Source

pub fn danger_accept_invalid_certs(&mut self, accept_invalid_certs: bool)

Sets if requests created from this Session will accept invalid TLS certificates.

Accepting invalid certificates implies that invalid hostnames are accepted as well.

The default value is false.

§Danger

Use this setting with care. This will accept any TLS certificate valid or not. If you are using self signed certificates, it is much safer to add their root CA to the list of trusted root CAs by your system.

Source

pub fn danger_accept_invalid_hostnames( &mut self, accept_invalid_hostnames: bool, )

Sets if requests created from this Session will accept an invalid hostname in a TLS certificate.

The default value is false.

§Danger

Use this setting with care. This will accept TLS certificates that do not match the hostname.

Source

pub fn add_root_certificate(&mut self, cert: Certificate)

Adds a root certificate that will be trusted by requests created from this Session.

Trait Implementations§

Source§

impl Clone for Session

Source§

fn clone(&self) -> Session

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Session

Source§

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

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

impl Default for Session

Source§

fn default() -> Session

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

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T