use super::SetOpt;
use curl::easy::Easy2;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum RedirectPolicy {
None,
Follow,
Limit(u32),
}
impl Default for RedirectPolicy {
fn default() -> Self {
RedirectPolicy::None
}
}
impl SetOpt for RedirectPolicy {
fn set_opt<H>(&self, easy: &mut Easy2<H>) -> Result<(), curl::Error> {
match self {
RedirectPolicy::Follow => {
easy.follow_location(true)?;
}
RedirectPolicy::Limit(max) => {
easy.follow_location(true)?;
easy.max_redirections(*max)?;
}
RedirectPolicy::None => {
easy.follow_location(false)?;
}
}
Ok(())
}
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct AutoReferer;
impl SetOpt for AutoReferer {
fn set_opt<H>(&self, easy: &mut Easy2<H>) -> Result<(), curl::Error> {
easy.autoreferer(true)
}
}