Skip to main content

RedirectPolicy

Enum RedirectPolicy 

Source
pub enum RedirectPolicy {
    None,
    Follow {
        max_redirects: usize,
    },
}
Expand description

Redirect behavior for a request.

Variants§

§

None

Do not follow redirects automatically.

§

Follow

Follow redirects up to max_redirects.

Fields

§max_redirects: usize

Maximum number of redirect hops to follow.

Implementations§

Source§

impl RedirectPolicy

Source

pub const fn none() -> Self

Convenience constructor for RedirectPolicy::None.

Source

pub const fn follow(max_redirects: usize) -> Self

Convenience constructor for RedirectPolicy::Follow.

Examples found in repository?
examples/request-builder/main.rs (line 16)
14fn main() -> Result<(), Box<dyn Error>> {
15    let url = "http://example.com";
16    let mut request = Request::get(url)?.with_redirect_policy(RedirectPolicy::follow(5));
17
18    request.add_header("Accept", "text/html,application/xhtml+xml")?;
19    request.add_header("Cache-Control", "max-age=0")?;
20    request.if_none_match("\"demo-etag\"")?;
21    request.if_modified_since(UNIX_EPOCH + Duration::from_secs(784_111_777))?;
22    request.range_bytes(Some(0), Some(255))?;
23
24    // Protocol-managed headers such as Host and Connection are intentionally rejected by the
25    // library. This example only uses safe end-to-end request headers.
26    let response = request.execute()?;
27
28    println!("manual request to {url}");
29    println!(
30        "status: {} {}",
31        response.status_code, response.reason_phrase
32    );
33    println!("content-type: {:?}", response.header("content-type"));
34    println!("body preview: {}", preview_text(response.body_text()?, 80));
35
36    Ok(())
37}
Source

pub fn max_redirects(self) -> Option<usize>

Returns the configured redirect limit for RedirectPolicy::Follow, otherwise None.

Trait Implementations§

Source§

impl Clone for RedirectPolicy

Source§

fn clone(&self) -> RedirectPolicy

Returns a duplicate 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 RedirectPolicy

Source§

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

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

impl PartialEq for RedirectPolicy

Source§

fn eq(&self, other: &RedirectPolicy) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for RedirectPolicy

Source§

impl Eq for RedirectPolicy

Source§

impl StructuralPartialEq for RedirectPolicy

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.